我在pom.xml
中添加了一个依赖项<dependency>
<groupId>com.company.location.my1</groupId>
<artifactId>sMyWebservice-module-services</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
但由于例外情况,我无法启动我的网络服务:Field myService in com.company.my.webservice.controllers.MyController required a bean of type 'com.company.location.my1.webservice.my.MyService' that could not be found.
所以我将springbootapplication改为
@SpringBootApplication
(scanBasePackages = {
"com.company.location.my1", //what I added to my pom
"com.company.my.webservice" //current parent package, not necessary
})
public class WebserviceApplication {
所以我会扫描包
并在MyController
中使用它
@Autowired
private MyService myService;
@PostMapping
public MyResponse activate(){
return myService.activate();
}
答案 0 :(得分:0)
验证MyService
类是否使用@Service
或@Configuration
进行注释。
如果MyService
未注释,您可以在WebserviceApplication
类中使用@Bean
定义一个方法,该方法将为您创建实例:
@Bean
public MyService myService() {
return new MyService();
}