Search in sources :

Example 1 with ConditionalOnProperty

use of org.springframework.boot.autoconfigure.condition.ConditionalOnProperty in project spring-boot by spring-projects.

the class PersistenceExceptionTranslationAutoConfiguration method persistenceExceptionTranslationPostProcessor.

@Bean
@ConditionalOnMissingBean(PersistenceExceptionTranslationPostProcessor.class)
@ConditionalOnProperty(prefix = "spring.dao.exceptiontranslation", name = "enabled", matchIfMissing = true)
public static PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() {
    PersistenceExceptionTranslationPostProcessor postProcessor = new PersistenceExceptionTranslationPostProcessor();
    postProcessor.setProxyTargetClass(true);
    return postProcessor;
}
Also used : PersistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 2 with ConditionalOnProperty

use of org.springframework.boot.autoconfigure.condition.ConditionalOnProperty in project cas by apereo.

the class CasFiltersConfiguration method casCorsFilter.

@ConditionalOnProperty(prefix = "cas.httpWebRequest.cors", name = "enabled", havingValue = "true")
@Bean
@RefreshScope
public FilterRegistrationBean casCorsFilter() {
    final HttpWebRequestProperties.Cors cors = casProperties.getHttpWebRequest().getCors();
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(cors.isEnabled());
    config.setAllowedOrigins(cors.getAllowOrigins());
    config.setAllowedMethods(cors.getAllowMethods());
    config.setAllowedHeaders(cors.getAllowHeaders());
    config.setMaxAge(cors.getMaxAge());
    config.setExposedHeaders(cors.getExposedHeaders());
    source.registerCorsConfiguration("/**", config);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setName("casCorsFilter");
    bean.setAsyncSupported(true);
    bean.setOrder(0);
    return bean;
}
Also used : CorsFilter(org.springframework.web.filter.CorsFilter) UrlBasedCorsConfigurationSource(org.springframework.web.cors.UrlBasedCorsConfigurationSource) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HttpWebRequestProperties(org.apereo.cas.configuration.model.core.web.security.HttpWebRequestProperties) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with ConditionalOnProperty

use of org.springframework.boot.autoconfigure.condition.ConditionalOnProperty in project spring-boot by spring-projects.

the class JerseyAutoConfiguration method jerseyFilterRegistration.

@Bean
@ConditionalOnMissingBean(name = "jerseyFilterRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "filter")
public FilterRegistrationBean<ServletContainer> jerseyFilterRegistration() {
    FilterRegistrationBean<ServletContainer> registration = new FilterRegistrationBean<>();
    registration.setFilter(new ServletContainer(this.config));
    registration.setUrlPatterns(Arrays.asList(this.path));
    registration.setOrder(this.jersey.getFilter().getOrder());
    registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(this.path));
    addInitParameters(registration);
    registration.setName("jerseyFilter");
    registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
    return registration;
}
Also used : ServletContainer(org.glassfish.jersey.servlet.ServletContainer) DispatcherType(javax.servlet.DispatcherType) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RegistrationBean(org.springframework.boot.web.servlet.RegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 4 with ConditionalOnProperty

use of org.springframework.boot.autoconfigure.condition.ConditionalOnProperty in project spring-boot by spring-projects.

the class JerseyAutoConfiguration method jerseyServletRegistration.

@Bean
@ConditionalOnMissingBean(name = "jerseyServletRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
public ServletRegistrationBean<ServletContainer> jerseyServletRegistration() {
    ServletRegistrationBean<ServletContainer> registration = new ServletRegistrationBean<>(new ServletContainer(this.config), this.path);
    addInitParameters(registration);
    registration.setName(getServletRegistrationName());
    registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup());
    return registration;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RegistrationBean(org.springframework.boot.web.servlet.RegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)4 Bean (org.springframework.context.annotation.Bean)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)2 RegistrationBean (org.springframework.boot.web.servlet.RegistrationBean)2 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)2 DispatcherType (javax.servlet.DispatcherType)1 HttpWebRequestProperties (org.apereo.cas.configuration.model.core.web.security.HttpWebRequestProperties)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 PersistenceExceptionTranslationPostProcessor (org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor)1 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)1 UrlBasedCorsConfigurationSource (org.springframework.web.cors.UrlBasedCorsConfigurationSource)1 CorsFilter (org.springframework.web.filter.CorsFilter)1