我正在處理一個多模塊 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 模塊中使用屬性?
添加回答
舉報
0/150
提交
取消