With a little operation check, I want to register only the components I want to use in the DI container while avoiding that ComponentScan
scans all the components under the package of my class, but the" Bean definition file "and" New JavaConfig " Creating a "class" became ** troublesome **, and when I wrote it in the class I wanted to check the operation with momentum, it worked.
StaticNaInnnerClassDeJavaConfig.java
@SpringBootApplication(scanBasePackages = { "undefined.package" })
@Component
public class StaticNaInnnerClassDeJavaConfig {
private final SomeComponent component;
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(StaticNaInnnerClassDeJavaConfig.class, args);
}
public StaticNaInnnerClassDeJavaConfig(SomeComponent component) {
this.component = component;
}
public static class JavaConfig {
@Bean
public SomeComponent someComponent(@Autowired Properties properties) {
return new SomeComponent(properties);
}
}
public static class SomeComponent {
private final String someParam;
public SomeComponent(Properties proeprties) {
this.someParam = properties.getProperty("someParam");
}
}
}
Recommended Posts