我也有同樣的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