我也有同样的maven父模块像在网络和核心项目的组合@RestController类,春 - 需要自动装配在@Component类
家长 - 网(com.parent.test.web) - 核心(com.parent.test.core)
我想是指在核心项目网络模块依赖调用一些从网络模块
Web项目样本的API,
com.test.parent.web
public interface RestInterface {
public ResponseEntity load();
}
@RestController
public class RestInterfaceImpl implements RestInterface {
@Override
@RequestMapping(value = "/getData", method = RequestMethod.GET, produces = APPLICATION_JSON)
public @ResponseBody ResponseEntity<Object> load() {
}
}
核心工程样本,
com.test.parent.core
@Component
public class CoreImpl implements CoreInterface {
// Is this possible to autowire
@Autowired
private RestInterface restInterface;
public boolean getOptions() {
ResponseEntity<Object> results = restInterface.load();
for (Object o : results) {
//TODO
}
}
}
因为项目是相同的父POM模块中开发。所有的项目将被分组到一个弹簧桶中,并将部署到相同的环境中。因此,我想将Web项目依赖项引用到核心项目中,并尝试扫描核心项目中的Web类。
我想获得的几件事情澄清,
- 这是不是好办法?
- 如果是好方法,我们该如何实现?
- 如果不是那么什么是正确的方法?
您确定您的意思是将web模块项目添加为核心项目中的依赖项吗?并调用一个API不需要依赖添加。你的意思是什么? –
是的。我将接口称为依赖关系,而不是访问Web模块uri。通过标题来自动化将Web模块spring bean类自动装配到Spring核心项目中。 – user3095047