I have abcController
field which is null in my Abc.class:
@Service(id = "ABC", name = "service-abc") // THIS IS NOT SPRING ANNOTATION it marks class as Service Singleton, loads custom annotations like @AfterInitialization
@SpringBootApplication
@ComponentScan(basePackages = "com.package*")
@ComponentScan("healthchecker")
public class Abc {
@Autowired
AbcController abcController;
@AfterInitialization
public void afterInit() throws GwConfigurationException {
// initialize Spring Boot
SpringApplication application = new SpringApplication(Dmsgw.class);
// run with command line arguments
CmdLineArguments cmdLineArguments = new CmdLineArguments();
String[] args = cmdLineArguments.getArgStrings();
if (args == null) {
args = new String[0];
}
application.run(args);
abcController.doSomething(); // abcController is null
}
}
This is my AbcController.class:
@Service
public class AbcController {
...// some fields
...// some methods
}
I tried so far to annotate abcController
with @Service
or @Component
or @Controller
but it's the same.
This is MyServiceConfiguration.class
:
@Configuration
public class ServiceConfiguration {
@Bean
public AbcController defaultAbcController() {
return new AbcController();
}
}
I checked and the Bean was loaded.