spring - 在 java webapp 中,hsqldb url 不接受相对路径。是因为maven配置吗?

标签 spring maven jakarta-ee web-applications hsqldb

我正在开发一个由其他 2 个 maven 模块组成的 webapp。

我有代表数据库层的模型模块。它有 Spring 应用程序上下文test-model-config.xmltest/resources/META-INF用于测试和 test/resources' default package 中的属性文件.和 model-config.xmlresources/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-INFgeneral.properties模型和服务模块所需的所有属性。所以general.propertieswebapp-log4j.propertiesresources' 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/

相关文章:

java - 如何关闭 SLF4J 的日志记录?

java - 请帮助开始使用 eclipse、spring、maven 创建一个简单的项目

Spring Boot 在集成测试期间不解析 application.properties 中的自定义属性

java - mvn tomcat7 :deploy goal failed Cannot invoke Tomcat manager: Connection refused

maven - Groovy 在 Codehaus 关闭后安装 HTTPBuilder?

performance - 使用 EJB 的实例池如何提高性能?

jakarta-ee - 如何将 CDI session bean 从 HTTP session 传播到 WebSocket session ?

java - 在 doFilter 方法中获取 IllegalStateException

java - 自定义身份验证管理器配置

java - Eclipse 注释处理器不工作。哪里显示错误?