我正在开发一个由其他 2 个 maven 模块组成的 webapp。
我有代表数据库层的模型模块。它有 Spring 应用程序上下文test-model-config.xml
在 test/resources/META-INF
用于测试和 test/resources' default package
中的属性文件.和 model-config.xml
在 resources/META-INF
这是实时上下文,应该从 webapp 中选择属性。
到目前为止,构建良好,工作正常没问题
- <!-- test-model-config.xml and model-config.xml have the same thing-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
这只是 test/resources 中属性的一个片段
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.username=sa
jdbc.password=
jdbc.url=jdbc:hsqldb:file:target/mydb;create=true
还有另一个模块服务具有相同类型的配置,其中有一个测试配置和一个实时配置文件。这个单独也没有问题。构建良好,工作正常。
现在webapp有
webapp-config.xml
在 /web pages/WEB-INF
和 general.properties
模型和服务模块所需的所有属性。所以general.properties
和 webapp-log4j.properties
在 resources' default package
webapp.here 的片段 webapp-config.xml
<import resource="classpath:META-INF/model-config.xml" />
<import resource="classpath:META-INF/service-config.xml" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:general.properties</value>
<value>classpath:webapp-log4j.properties</value>
</list>
</property>
</bean>
在 general.properties 我们有
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.username=sa
jdbc.password=
jdbc.url=jdbc:hsqldb:file:classpath:target/mynewdb;create=true
// ....
它也可以很好地构建并在出现问题时运行良好。
1 :日志说:
java.sql.SQLException: File input/output error classpath:target/mynewdb.properties java.io.FileNotFoundException: classpath:target/mynewdb.properties.new (No such file or directory) full debug output is here
我真的很惊讶,因为这是我第一次遇到这种错误。它运行良好,绝对网址为
/media/Repo/myproject/mydb;create=true
,但想法是将它放在 webapp 目标中,以便在删除目标文件夹时将其删除。好吧,我不知道,现在已经 2 天了。
id 如何解决这个问题?这里有什么我没有看到/做的事情吗?是因为maven配置吗?
我的 pom 是可见的 here
感谢您阅读本文。
最佳答案
我相信 jdbc.url
的语法在 general.properties
不正确 - 您不能指定 classpath
file
的位置- 它必须是绝对或相对路径。引用jdbcConnection javadoc
关于spring - 在 java webapp 中,hsqldb url 不接受相对路径。是因为maven配置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5998972/