多模块组件扫描在弹簧启动时不起作用
2022-09-03 17:59:28
我有两个模块网络和业务。我已经将业务纳入网络。但是当我尝试使用将服务接口从业务合并到Web中时,它正在给出.@autowired
org.springframework.beans.factory.NoSuchBeanDefinitionException
所以,基本上无法从业务模块中扫描。@SpringBootApplication
@Service
是不是很简单,我错过了?
如果我在类中添加该服务,则它工作正常。@Bean
@SpringBootApplication
法典:
package com.manish;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class SpringBootConfiguration {
public static void main(String[] args) {
SpringApplication.run(SpringBootConfiguration.class, args);
}
}
模块 1 中的类,从中调用模块 2 中的类:
package com.manish.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.co.smithnews.pmp.service.contract.UserRegistrationService;
@RestController
@RequestMapping("/testManish")
public class SampleController {
@Autowired
private SampleService sampleService;
....
}
模块 2:
package com.manish.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SampleServiceImpl implements SampleService {
}
谢谢