下面列出了org.springframework.boot.autoconfigure.web.ResourceProperties#org.springframework.boot.autoconfigure.web.ServerProperties 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public RequestForwarder(
ServerProperties serverProperties,
FaradayProperties faradayProperties,
HttpClientProvider httpClientProvider,
MappingsProvider mappingsProvider,
LoadBalancer loadBalancer,
Optional<MeterRegistry> meterRegistry,
ProxyingTraceInterceptor traceInterceptor,
PostForwardResponseInterceptor postForwardResponseInterceptor
) {
this.serverProperties = serverProperties;
this.faradayProperties = faradayProperties;
this.httpClientProvider = httpClientProvider;
this.mappingsProvider = mappingsProvider;
this.loadBalancer = loadBalancer;
this.meterRegistry = meterRegistry;
this.traceInterceptor = traceInterceptor;
this.postForwardResponseInterceptor = postForwardResponseInterceptor;
}
@Test
public void testShouldReturnEndpointsWithoutContextPath() {
WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
ServerProperties properties = new ServerProperties();
properties.getServlet().setContextPath("foo");
EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
ExposableWebEndpoint infoEndpoint = createEndpoint("info");
ExposableWebEndpoint healthEndpoint = createEndpoint("health");
return Arrays.asList(infoEndpoint, healthEndpoint);
};
Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
.skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
.pattern();
then(pattern).isNotEmpty();
then(pattern.get().pattern())
.isEqualTo("/actuator/(info|info/.*|health|health/.*)");
}
public H2DbProperties(
@Autowired(required = false) ConfigurableEnvironment environment,
@Autowired(required = false) ServerProperties serverProperties) {
String applicationName = "application";
Integer port = 0;
if (Objects.nonNull(environment)) {
applicationName = environment.getProperty("spring.application.name");
}
if (Objects.nonNull(serverProperties)) {
port = serverProperties.getPort();
}
this.filePath = System.getProperty("user.dir") +
File.separator +
".txlcn" +
File.separator +
(StringUtils.hasText(applicationName) ? applicationName : "application") +
"-" + port;
}
@SuppressWarnings("ConstantConditions")
public BackstopperSpringboot2ContainerErrorController(
@NotNull ProjectApiErrors projectApiErrors,
@NotNull UnhandledServletContainerErrorHelper unhandledServletContainerErrorHelper,
@NotNull ServerProperties serverProperties
) {
if (projectApiErrors == null) {
throw new NullPointerException("ProjectApiErrors cannot be null.");
}
if (unhandledServletContainerErrorHelper == null) {
throw new NullPointerException("UnhandledServletContainerErrorHelper cannot be null.");
}
if (serverProperties == null) {
throw new NullPointerException("ServerProperties cannot be null.");
}
this.projectApiErrors = projectApiErrors;
this.unhandledServletContainerErrorHelper = unhandledServletContainerErrorHelper;
this.errorPath = serverProperties.getError().getPath();
}
@Autowired
public LightminClientProperties(final ManagementServerProperties managementServerProperties,
final ServerProperties serverProperties,
@Value("${spring.batch.lightmin.application-name:null}") final String name,
@Value("${endpoints.health.id:health}") final String healthEndpointId,
final WebEndpointProperties webEndpointProperties,
final Environment environment) {
if (name == null || "null".equals(name)) {
this.name = environment.getProperty("spring.application.name", "spring-boot-application");
} else {
this.name = name;
}
this.healthEndpointId = healthEndpointId;
this.managementServerProperties = managementServerProperties;
this.serverProperties = serverProperties;
this.webEndpointProperties = webEndpointProperties;
}
public FaradayConfiguration(FaradayProperties faradayProperties,
ServerProperties serverProperties,
StaffjoyPropreties staffjoyPropreties,
AssetLoader assetLoader) {
this.faradayProperties = faradayProperties;
this.serverProperties = serverProperties;
this.staffjoyPropreties = staffjoyPropreties;
this.assetLoader = assetLoader;
}
public ProgrammaticMappingsProvider(
EnvConfig envConfig,
ServerProperties serverProperties,
FaradayProperties faradayProperties,
MappingsValidator mappingsValidator,
HttpClientProvider httpClientProvider
) {
super(serverProperties, faradayProperties, mappingsValidator, httpClientProvider);
this.envConfig = envConfig;
}
public MappingsProvider(
ServerProperties serverProperties,
FaradayProperties faradayProperties,
MappingsValidator mappingsValidator,
HttpClientProvider httpClientProvider
) {
this.serverProperties = serverProperties;
this.faradayProperties = faradayProperties;
this.mappingsValidator = mappingsValidator;
this.httpClientProvider = httpClientProvider;
}
public ConfigurationMappingsProvider(
ServerProperties serverProperties,
FaradayProperties faradayProperties,
MappingsValidator mappingsValidator,
HttpClientProvider httpClientProvider
) {
super(serverProperties, faradayProperties,
mappingsValidator, httpClientProvider);
}
public DefaultErrorController(ErrorAttributes errorAttributes, ServerProperties properties) {
super(errorAttributes == null ? new DefaultErrorAttributes() : errorAttributes);
if (properties == null) {
errorProperties = new ErrorProperties();
errorProperties.setPath("/error");
} else {
this.errorProperties = properties.getError();
}
}
public ErrorHandlerConfig(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
public CustomErrorWebFluxAutoConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
public ErrorHandlerConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
/**
* 路由加载器
*
* @return
*/
@Bean
public JdbcRouteLocator jdbcRouteLocator(ZuulProperties zuulProperties, ServerProperties serverProperties, JdbcTemplate jdbcTemplate, ApplicationEventPublisher publisher) {
jdbcRouteLocator = new JdbcRouteLocator(serverProperties.getServlet().getContextPath(), zuulProperties, jdbcTemplate, publisher);
log.info("JdbcRouteLocator:{}", jdbcRouteLocator);
return jdbcRouteLocator;
}
public FwGatewayErrorConfigure(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
public ErrorHandlerConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
public ErrorHandlerConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public CloudFoundryApplicationFactory applicationFactory(InstanceProperties instance,
ManagementServerProperties management, ServerProperties server, PathMappedEndpoints pathMappedEndpoints,
WebEndpointProperties webEndpoint, ObjectProvider<List<MetadataContributor>> metadataContributors,
CloudFoundryApplicationProperties cfApplicationProperties) {
return new CloudFoundryApplicationFactory(instance, management, server, pathMappedEndpoints, webEndpoint,
new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
cfApplicationProperties);
}
public ErrorHandler(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
/**
* Instantiates a new Error handler configuration.
*
* @param serverProperties the server properties
* @param resourceProperties the resource properties
* @param viewResolversProvider the view resolvers provider
* @param serverCodecConfigurer the server codec configurer
* @param applicationContext the application context
*/
public ErrorHandlerConfiguration(final ServerProperties serverProperties,
final ResourceProperties resourceProperties,
final ObjectProvider<List<ViewResolver>> viewResolversProvider,
final ServerCodecConfigurer serverCodecConfigurer,
final ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
public ErrorHandlerConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
WebEndpointProperties webEndpoint, ObjectProvider<List<MetadataContributor>> metadataContributors,
DispatcherServletPath dispatcherServletPath) {
return new ServletApplicationFactory(instance, management, server, servletContext, pathMappedEndpoints,
webEndpoint,
new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
dispatcherServletPath);
}
public DynamicRouteConfiguration(Registration registration, DiscoveryClient discovery,
ZuulProperties zuulProperties, ServerProperties server, RedisTemplate redisTemplate) {
this.registration = registration;
this.discovery = discovery;
this.zuulProperties = zuulProperties;
this.server = server;
this.redisTemplate = redisTemplate;
}
/**
* Registers a custom {@link ErrorController} to change the default error handling approach.
*
* @param errorAttributes Will be used to enrich error responses.
* @param serverProperties Will be used to access error related configurations.
* @param errorViewResolvers All possible view resolvers to render the whitelabel error page.
* @return The custom error controller instance.
*/
@Bean
@ConditionalOnBean(WebErrorHandlers.class)
@ConditionalOnMissingBean(ErrorController.class)
public BasicErrorController customErrorController(ErrorAttributes errorAttributes,
ServerProperties serverProperties,
ObjectProvider<ErrorViewResolver> errorViewResolvers) {
List<ErrorViewResolver> resolvers = errorViewResolvers.orderedStream().collect(toList());
return new CustomServletErrorController(errorAttributes, serverProperties.getError(), resolvers);
}
@Test
public void testExtractorsCount() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
BusConfig.class, EnvironmentMonitorAutoConfiguration.class,
ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
PropertyPlaceholderAutoConfiguration.class).properties("server.port=-1")
.run();
PropertyPathEndpoint endpoint = context.getBean(PropertyPathEndpoint.class);
assertThat(((Collection<?>) ReflectionTestUtils.getField(
ReflectionTestUtils.getField(endpoint, "extractor"), "extractors"))
.size()).isEqualTo(7);
context.close();
}
public ExceptionAutoConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider
.getIfAvailable(() -> Collections.emptyList());
this.serverCodecConfigurer = serverCodecConfigurer;
}
public ExceptionAutoConfiguration(ServerProperties serverProperties,
ResourceProperties resourceProperties,
ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer,
ApplicationContext applicationContext) {
this.serverProperties = serverProperties;
this.applicationContext = applicationContext;
this.resourceProperties = resourceProperties;
this.viewResolvers = viewResolversProvider
.getIfAvailable(() -> Collections.emptyList());
this.serverCodecConfigurer = serverCodecConfigurer;
}
@Test
public void should_return_empty_when_no_endpoints() {
EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = Collections::emptyList;
Optional<Pattern> pattern = new SkipPatternConfiguration.ActuatorSkipPatternProviderConfig()
.skipPatternForActuatorEndpointsSamePort(new ServerProperties(),
new WebEndpointProperties(), endpointsSupplier)
.skipPattern();
then(pattern).isEmpty();
}
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
ObjectProvider<List<MetadataContributor>> metadataContributors) {
return new DefaultApplicationFactory(instance, management, server, pathMappedEndpoints, webEndpoint,
new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)));
}
@Before
public void beforeMethod() {
projectApiErrorsMock = mock(ProjectApiErrors.class);
unhandledContainerErrorHelperMock = mock(UnhandledServletContainerErrorHelper.class);
servletRequestMock = mock(ServletRequest.class);
serverPropertiesMock = mock(ServerProperties.class);
errorPropertiesMock = mock(ErrorProperties.class);
errorPath = UUID.randomUUID().toString();
doReturn(errorPropertiesMock).when(serverPropertiesMock).getError();
doReturn(errorPath).when(errorPropertiesMock).getPath();
}