I am new to spring boot & facing one issue. I have a class that I want to @Autowired
it in controller. But I am getting an error.
Description:
Field sessionService in co.business.controller.SessionController required a bean of type 'co.business.service.AppSessionService' that could not be found.
Action:
Consider defining a bean of type 'co.business.service.AppSessionService' in your configuration.
Here is my component class.
package co.business.service;
...
@Component
public class AppSessionService {
@Autowired
public AppSessionService() {
super();
}
...
}
Here is my controller.
package co.business.controller;
...
@RestController
@RequestMapping("/session")
public class SessionController {
@Autowired
private AppSessionService sessionService;
@PostMapping(path = "/cfck", consumes = "application/json", produces = "application/json")
public Map<String, Boolean> isRegister(@RequestBody AppSession session){
// Some stuff here
return map;
}
...
}
I applied solution provided in this question. but could not work for me still having same error.
Main class.
@ComponentScan({"co.business.service", "co.business.controller"})
@SpringBootApplication
public class BusinessMainApplication {
public static void main(String[] args) {
SpringApplication.run(BusinessMainApplication.class, args);
}
}
It could be a duplicate question but I tried to apply solutions from some previous questions but none could solve my problem as I explained above.
Can any one explain the complete solution to solve this problem.