无法在 spring 中使用 PropertiesFactoryBean 和 PropertyPlaceholderConfigurer 正确导入 Maven 属性

Cannot import correctly maven properties with PropertiesFactoryBean and PropertyPlaceholderConfigurer in spring

我遇到了 jdbc 动态属性配置器的问题。我试着解释到底是什么问题。

当我执行 mvn clean install 并且在我将应用程序部署到我的服务器 (Weblogic 10.3.3) 之后,一切都是正确的,所有应用程序都运行良好。但是,每天早上,当我尝试重新部署相同的应用程序时,都会显示如下错误消息:

Error creating bean with name 'path.to.my.bean.JDBCPropertiesFactoryBean#6015a10' defined in class path resource [spring/configuration/placeholder-jdbcproperties.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [
SELECT
  A.COLUMN1 || '.' || P.COLUMN2,
  COLUMN3
FROM
  T_TABLE_WITH_PROPERTIES${application.version} P,
  T_TABLE_WITH_PROPERTIES_2 G
WHERE G.ID = P.ID
]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

这个application.version来自maven pom.xml:

<properties>
  ...
  <application.version>MyVersion</application.version>
  ...
</properties>

豆子是:

<bean id="jdbcPlaceholderConfig"
class="path.to.my.bean.DefaultPropertyPlaceholderConfigurer"> <!-- Class to extend PropertyPlaceholderConfigurer -->
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="properties">
    <bean class="path.to.my.bean.JDBCPropertiesFactoryBean"> <!-- Class to extend PropertiesFactoryBean -->
        <property name="query">
            <value>
                SELECT
                    A.COLUMN1 || '.' || P.COLUMN2,
                    COLUMN3
                FROM
                    T_TABLE_WITH_PROPERTIES${application.version} P,
                    T_TABLE_WITH_PROPERTIES_2 G
                WHERE G.ID = P.ID
            </value>
        </property>
        <property name="dataSource" ref="ref.to.datasource.bean"/>
    </bean>
</property>

所以,每天早上我都必须用 maven 重建,循环又开始了。

其他信息:我也尝试使用 JRebel,但我不确定问题出在哪里,也许这是相关的。

提前致谢。

更新:

这是我如何生成 rebel.xml:

<build>
  ...
  <plugins>
    <plugin>
      <groupId>org.zeroturnaround</groupId>
      <artifactId>jrebel-maven-plugin</artifactId>
      <version>1.1.5</version>
      <configuration>
        <relativePath>../../</relativePath>
        <rootPath>PATH\TO\MY\SIS_VOB</rootPath>
        <addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>
        <alwaysGenerate>true</alwaysGenerate>
      </configuration>
      <executions>
        <execution>
          <id>generate-rebel-xml</id>
          <phase>process-resources</phase>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

我刚刚意识到使用 <executions>...<goal>generate</goal>...</executions> 时,当我使用 mvn clean install 而没有使用 jrebel:generate 时,总是会生成 rebel.xml 文件,所以也许我必须删除执行标记,并使用 jrebel:generate 生成一次 rebel.xml 文件,然后编辑 rebel.xml 并再次执行 mvn clean install.

这样对吗?

谢谢。

更新解决方案:

这是 pom.xml:

中 maven jrebel 插件的最终版本
<build>
  ...
  <plugins>
    <plugin>
      <groupId>org.zeroturnaround</groupId>
      <artifactId>jrebel-maven-plugin</artifactId>
      <version>1.1.5</version>
      <configuration>
        <relativePath>../../</relativePath>
        <rootPath>PATH\TO\MY\SIS_VOB</rootPath>
        <addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>
        <alwaysGenerate>true</alwaysGenerate>
      </configuration>
      <!-- executions tag out! to not regenerate files always -->
    </plugin>
  </plugins>
</build>

创建 rebel.xml:

mvn jrebel:generate

然后,如果我们想要,我们可以修改 rebel.xml 文件,如果我们想排除一些文件,比如 *.properties,作为 Henri 的回答。

就是这样!

如果您在 JRebel 中使用资源过滤,就会发生这种情况,因为应用程序会从项目工作目录(根据 rebel.xml)以未过滤的形式查找 bean 的 xml。 =14=]

要解决此问题,您需要更新该模块的 rebel.xml,为特定的 XML 文件添加排除项 - 请参阅 here

Example