jjzjj

ComponentScan

全部标签

java - Spring boot ComponentScan excludeFIlters 不排除

我正在进行SimpleTest:@RunWith(SpringRunner.class)@SpringBootTest(classes=SimpleTestConfig.class)publicclassSimpleTest{@Testpublicvoidtest(){assertThat(true);}}以及此测试的配置:@SpringBootApplication@ComponentScan(basePackageClasses={SimpleTestConfig.class,Application.class},excludeFilters=@ComponentScan.Filt

java - Spring boot ComponentScan excludeFIlters 不排除

我正在进行SimpleTest:@RunWith(SpringRunner.class)@SpringBootTest(classes=SimpleTestConfig.class)publicclassSimpleTest{@Testpublicvoidtest(){assertThat(true);}}以及此测试的配置:@SpringBootApplication@ComponentScan(basePackageClasses={SimpleTestConfig.class,Application.class},excludeFilters=@ComponentScan.Filt

java - Spring - @Primary 对 @ComponentScan 失败?

对于一个简单的POJO:@ComponentpublicclassFoo{privatefinalStringstring;publicFoo(){this("SecondaryComponentScan??");}publicFoo(Stringstring){this.string=string;}@OverridepublicStringtoString(){returnstring;}}还有这个配置@Configuration@ComponentScan(basePackageClasses=Foo.class)publicclassTestConfiguration{@Pri

java - Spring - @Primary 对 @ComponentScan 失败?

对于一个简单的POJO:@ComponentpublicclassFoo{privatefinalStringstring;publicFoo(){this("SecondaryComponentScan??");}publicFoo(Stringstring){this.string=string;}@OverridepublicStringtoString(){returnstring;}}还有这个配置@Configuration@ComponentScan(basePackageClasses=Foo.class)publicclassTestConfiguration{@Pri

java - @ComponentScan 在 Spring Boot AutoConfiguration 类中不起作用?

我正在尝试创建一个新的启动器。我有一个业务模块,比如ProjectManager,其中包含一些用@Component注释的类。按照教程,我创建了一个自动配置模块,它包含一个AutoConfiguration类。首先,我尝试使用@ComponentSan在我的业务模块中查找bean。@ComponentScan(value={"com.foo.project"})@ConditionalOnClass({Project.class})@ConfigurationpublicclassProjectAutoConfiguration{....}但它不起作用。我必须添加额外的配置类如下:@C

java - @ComponentScan 在 Spring Boot AutoConfiguration 类中不起作用?

我正在尝试创建一个新的启动器。我有一个业务模块,比如ProjectManager,其中包含一些用@Component注释的类。按照教程,我创建了一个自动配置模块,它包含一个AutoConfiguration类。首先,我尝试使用@ComponentSan在我的业务模块中查找bean。@ComponentScan(value={"com.foo.project"})@ConditionalOnClass({Project.class})@ConfigurationpublicclassProjectAutoConfiguration{....}但它不起作用。我必须添加额外的配置类如下:@C

java - 如何在 Spring 中使用 @ComponentScan 懒惰地加载所有 bean?

我正在使用基于Java的配置来设置我的Spring应用程序上下文,如下所示:@Configuration@Lazy@ComponentScan(basePackageClasses={MyProject.class,OtherProject.class})publicclassMyAppConfig{...}在配置中显式定义的Bean会像您期望的那样延迟加载。但是,使用@Named注释的扫描类总是急切地加载。我该如何解决这个问题?感谢任何帮助。请注意,对于MyProject中的类包,我可以通过使用@Lazy注释它们来解决这个问题也是。但是另一个项目不依赖于Spring,我想保持它这样(

java - 如何在 Spring 中使用 @ComponentScan 懒惰地加载所有 bean?

我正在使用基于Java的配置来设置我的Spring应用程序上下文,如下所示:@Configuration@Lazy@ComponentScan(basePackageClasses={MyProject.class,OtherProject.class})publicclassMyAppConfig{...}在配置中显式定义的Bean会像您期望的那样延迟加载。但是,使用@Named注释的扫描类总是急切地加载。我该如何解决这个问题?感谢任何帮助。请注意,对于MyProject中的类包,我可以通过使用@Lazy注释它们来解决这个问题也是。但是另一个项目不依赖于Spring,我想保持它这样(

spring - 如何在 SpringJunit4TestRunner 中将 @ComponentScan 与特定于测试的 ContextConfigurations 一起使用?

我正在测试一个SpringBoot应用程序。我有几个测试类,每个测试类都需要一组不同的模拟或其他自定义bean。这是设置的草图:src/main/java:packagecom.example.myapp;@SpringBootApplication@ComponentScan(basePackageClasses={MyApplication.class,ImportantConfigurationFromSomeLibrary.class,ImportantConfigurationFromAnotherLibrary.class})@EnableFeignClients@Enab

spring - 如何在 SpringJunit4TestRunner 中将 @ComponentScan 与特定于测试的 ContextConfigurations 一起使用?

我正在测试一个SpringBoot应用程序。我有几个测试类,每个测试类都需要一组不同的模拟或其他自定义bean。这是设置的草图:src/main/java:packagecom.example.myapp;@SpringBootApplication@ComponentScan(basePackageClasses={MyApplication.class,ImportantConfigurationFromSomeLibrary.class,ImportantConfigurationFromAnotherLibrary.class})@EnableFeignClients@Enab