【发布时间】:2016-08-05 20:10:39
【问题描述】:
我在同一个 maven 父模块下有 web 和核心项目的组合,
父母 - 网络(com.parent.test.web) - 核心(com.parent.test.core)
我想引用核心项目中的web模块依赖来调用web模块中的一些api
Web 项目示例,
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 模块中开发的。所有项目将被分组到一个 springboot jar 中,并将部署到同一个环境中。所以,我想把 web 项目的依赖引用到 core 项目中,并尝试扫描 core 项目中的 web 类。
我想澄清一些事情,
- 这是好方法吗?
- 如果是好方法,我们该如何实施?
- 如果不是,那么正确的方法是什么?
【问题讨论】:
-
您确定要在核心项目中添加 web 模块项目作为依赖项吗?并且调用 API 不需要添加依赖项。你说的标题是什么意思?
-
是的。我将接口称为依赖项,而不是访问 Web 模块 uri。标题的意思是将 web 模块 spring bean 类自动装配到 spring 核心项目中。