@Autowired in SpringSecurity Configuration

时间:2013-10-15 15:25:03

标签: java spring spring-security autowired

我有类似的Spring Security配置:

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private DataSource dataSource;
    @Override
    ....

ide告诉我无法自动装配dataSource,但我在RootConfiguration类中配置了dataSource bean:

    @Configuration
    @EnableTransactionManagement
    @PropertySource("classpath:application.properties")
    @EnableJpaRepositories("com.zero.mvc.repository")
    @ComponentScan("com.zero.mvc")
    @Import(SecurityConfig.class)
    public class RootConfiguration {
    ....
    @Bean
    public DataSource dataSource() 
    ...

我不明白为什么...... 谢谢!

1 个答案:

答案 0 :(得分:0)

我认为你可能会错过一个导入注释,如: @Import(value = {SomeOtherConfig.class})

例如,可以在这里找到一个例子: http://examples.javacodegeeks.com/enterprise-java/spring/beans-spring/spring-3-java-config-import-example/