亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在多模塊 Spring Boot 項目中使用屬性

在多模塊 Spring Boot 項目中使用屬性

神不在的星期二 2021-09-15 17:21:33
我正在處理一個多模塊 spring boot 項目,遇到了與 application.properties 文件中保存的屬性有關的問題。從頭開始:目前我有兩個模塊:數據和網絡。項目結構如下所示:parent project      |_ data      |_ web模塊在父 pom 文件中正確命名<modules>    <module>data</module>    <module>web</module></modules>數據模塊負責連接到數據庫并定義用于數據訪問的存儲庫。它在它的 application.properties 文件中有一些屬性,用于保存到數據庫的連接詳細信息spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XEspring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriverspring.datasource.username=XXXXXXXXspring.datasource.password=XXXXXXXXX在 web 模塊中,我想從數據庫中讀取數據并將其放入 jsp。所以我在 web-module 的 pom 中添加了一個對 data-module 的依賴:<dependency>     <groupId>de.my.fancy.groupId</groupId>    <artifactId>data</artifactId>     <version>${project.version}</version></dependency>啟動網絡模塊時,我收到此錯誤:***************************APPLICATION FAILED TO START***************************Description:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class我想我可能必須從數據模塊中注入我的配置類,所以我像這樣更改了 web 模塊的起始類:@SpringBootApplication(exclude= {SecurityAutoConfiguration.class}, scanBasePackageClasses= {JPAConfig.class})public class WebApplication {    @Autowired    JPAConfig config;    public static void main(String[] args) {        SpringApplication.run(WebApplication.class, args);    }}因此,似乎我無法從數據模塊中的 application.properties 中獲取要在 web 模塊中注入的配置對象中使用的屬性。我可以在這里做什么才能在 web 模塊中使用屬性?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號