spring IoC:将 ComponentScan 放在哪里

问题描述

这是我的弹簧配置器:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
@Slf4j
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        log.info("Web security performing");

        http
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
        .cors().and()
        .csrf().disable()
        .authorizeRequests().anyRequest().permitAll();

        log.info("Web security performed");
    }
}

尽管如此,它从未达到过。

这是我的应用程序类:

@ComponentScan({
    "cat.gencat.catsalut.hes.core.domain.mpi","cat.gencat.catsalut.hes.core.repository"
})
@SpringBootApplication(exclude = JmxAutoConfiguration.class)
public class ProjectApplication {

如您所见,@ComponentScan 位于主 ProjectApplication 类中。

我意识到当我从主 @ComponentScan 类中删除 ProjectApplication 时,会检测到我的 WebSecurityConfiguration

当它存在时,WebSecurityConfiguration 将被忽略。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)