spring-java-config

java.lang.IllegalArgumentException: Failed to register servlet with name 'dispatcher'.Check if there is another servlet registered under the same name

a 夏天 提交于 2019-12-20 06:33:12
问题 My initializer class public class HomeServlet extends AbstractAnnotationConfigDispatcherServletInitializer{ @Override protected Class<?>[] getRootConfigClasses() { return null; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{SpringContextConfig1.class}; } @Override protected String[] getServletMappings() { return new String[] {"/home"}; } } Configuration Class @ComponentScan(basePackages={"spittr.controllers"}) @Configuration @EnableWebMvc public class

springSecurityFilterChain nullPointer Exception

对着背影说爱祢 提交于 2019-12-20 03:00:09
问题 When I try to run project, the Tomcat return an exception. Some one can help with this problem? Configuration class: https://github.com/intrade/inventory/blob/master/src/main/java/com/springapp/mvc/InitApp/SecurityConfig.java Stack trace: Jan 24, 2014 4:09:40 PM org.apache.catalina.core.ApplicationContext log org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config

Spring Security OAuth2 with custom TokenGranter in version 2.0.+

拈花ヽ惹草 提交于 2019-12-19 16:37:00
问题 In previous versions of OAuth2 it was possible to add a custom token granter by adding it to the xml configuration in the <authorization-server> element. I wonder how I could extend the authorization server with Java Config using a AuthorizationServerConfigurerAdapter, without losing the default configuration, which contains the implicit, client credentials, refresh token and authorization code grant types. First attempt was using creating the TokenGranter with @Component: @Component(

How do I delay evaluation of a Spring @Conditional configuration annotation?

无人久伴 提交于 2019-12-18 15:12:05
问题 I have a Spring @Configuration class that should register a bean when a specific property value is set in the environment. I wrote a custom Condition implementation that checked whether the value was present, and it works when I fire up the application in Spring Boot, but the bean was never registered when running JUnit tests. I debugged the application and determined that the Condition was being evaluated before the PropertySourcesPlaceholderConfigurer was being instantiated. I modified my

How do I delay evaluation of a Spring @Conditional configuration annotation?

荒凉一梦 提交于 2019-12-18 15:11:16
问题 I have a Spring @Configuration class that should register a bean when a specific property value is set in the environment. I wrote a custom Condition implementation that checked whether the value was present, and it works when I fire up the application in Spring Boot, but the bean was never registered when running JUnit tests. I debugged the application and determined that the Condition was being evaluated before the PropertySourcesPlaceholderConfigurer was being instantiated. I modified my

How do I delay evaluation of a Spring @Conditional configuration annotation?

丶灬走出姿态 提交于 2019-12-18 15:11:08
问题 I have a Spring @Configuration class that should register a bean when a specific property value is set in the environment. I wrote a custom Condition implementation that checked whether the value was present, and it works when I fire up the application in Spring Boot, but the bean was never registered when running JUnit tests. I debugged the application and determined that the Condition was being evaluated before the PropertySourcesPlaceholderConfigurer was being instantiated. I modified my

Spring Data JPA - How to programmatically set JpaRepository base packages

僤鯓⒐⒋嵵緔 提交于 2019-12-18 12:34:41
问题 When defining an EntityManager in a Spring Java Config class, I can add the base packages to scan for Entity classes by calling a method on the corresponding builder: public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) { // Some other configuration here builder.packages("org.foo.bar", "org.foo.baz"); return builder.build(); } I need something similar for the places where Spring looks for Repository Interfaces. The usual way is using the

Spring security authorize request for url & method using HttpSecurity

和自甴很熟 提交于 2019-12-18 12:12:15
问题 Is there any way to authorize post request to a specific url using org.springframework.security.config.annotation.web.builders.HttpSecurity ? I'm using HttpSecurity as: @Override protected void configure(HttpSecurity http) throws Exception { http .addFilterAfter(new CsrfCookieGeneratorFilter(), CsrfFilter.class) .exceptionHandling() .authenticationEntryPoint(authenticationEntryPoint) .and() .rememberMe() .rememberMeServices(rememberMeServices) .key(env.getProperty("jhipster.security

how to select which spring batch job to run based on application argument - spring boot java config

[亡魂溺海] 提交于 2019-12-18 02:50:39
问题 I have two independent spring batch jobs in the same project because I want to use the same infrastructure-related beans. Everything is configured in Java. I would like to know if there's a proper way to start the jobs independent based for example on the first java app argument in the main method for example. If I run SpringApplication.run only the second job gets executed by magic. The main method looks like: @ComponentScan @EnableAutoConfiguration public class Application { public static

Spring Java Config with Multiple Dispatchers

六月ゝ 毕业季﹏ 提交于 2019-12-17 23:25:51
问题 I've some experience Spring now and also have some pure java config web-apps in use. However, these are usually based on a quiet simple setup: application config for services / repositories dispatcher config for one dispatcher (and some controllers) (optional) spring security to secure the access For my current project I need to have separate dispatcher contexts with different configuration. That's not a problem with the XML based configuration as we have a dedicated ContextLoaderListener