我的项目有两个模块persistence
和services
如何在类路径中查找属性文件?
持久性/ MySqlDatabaseConfig看起来像
@Configuration
@Profile("default")
@PropertySources({
@PropertySource("classpath:resources/db.properties"),
@PropertySource(value = "file:/home/y/conf/pryme/db.properties", ignoreResourceNotFound = true)
})
public class MySqlDatabaseConfig extends JpaCommonConfig {
....
}
服务/ src目录/主/资源/ db.properties
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/newDB?createDatabaseIfNotExist=true
database.username=root
database.password=
也services
模块取决于persistence
模块
当我运行测试中,我看到错误的
Failed to load bean class: com.yahoo.comma.persistence.profiles.MySqlDatabaseConfig; nested exception is java.io.FileNotFoundException: class path resource [resources/db.properties] cannot be opened because it does not exist
如何访问性文件正确?
UPDATE
在services.war
,我看到它是在这里
374 Wed Jun 11 11:26:16 PDT 2014 WEB-INF/classes/pryme.properties
属性文件在哪里?您的应用程序期望它位于名为“resources”的子目录中,该子目录位于CLASSPATH中的子目录内(子目录是)。所以'资源'不需要在CLASSPATH中,但是它的父类可以。 – theglauber
它不重复。该解决方案不适用于这种情况 – daydreamer