春天无法使用PropertiesFactoryBean和PropertyPlaceholderConfigurer正确导入Maven属性 [英] Cannot import correctly maven properties with PropertiesFactoryBean and PropertyPlaceholderConfigurer in spring

查看:304
本文介绍了春天无法使用PropertiesFactoryBean和PropertyPlaceholderConfigurer正确导入Maven属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm facing problems with a jdbc dynamic properties configurer. I try to explain what exactly the problem is.

当我执行mvn clean install时,以及在将应用程序部署到服务器中之后(Weblogic 10.3.3),一切都正确,并且所有应用程序都可以正常工作.但是,每天早晨,当我尝试重新部署相同的应用程序时,都显示了一条错误消息,如下所示:

When I do mvn clean install and right after I deploy the applications in my server (Weblogic 10.3.3), everything is correct, and all the applications work fine. But, every morning, when I try to redeploy the same applications, it was shown an error message like this:

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:

This application.version comes from maven pom.xml:

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

bean是:

<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进行重建,然后循环再次开始.

So, every morning I have to rebuild with maven, and the loop starts again.

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

Additional information: I try to use JRebel too, but I'm not sure where can be the problem, maybe this is relevant.

谢谢.

更新:

这就是我生成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,然后再次执行mvn clean install.

I've just realized that with <executions>...<goal>generate</goal>...</executions>, when I do mvn clean install, without jrebel:generate, the rebel.xml files are always generated, so maybe I have to delete the executions tag, and generate the rebel.xml files once with jrebel:generate, and then, edit the rebel.xml and do again mvn clean install.

那是正确的吗?

谢谢.

使用解决方案更新:

这是pom.xml中的maven jrebel插件的最终版本:

This is the final version of maven jrebel plugin in the pom.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 tag out! to not regenerate files always -->
    </plugin>
  </plugins>
</build>

要创建rebel.xml,

To create the rebel.xml:

mvn jrebel:generate

然后,如果需要,如果我们想排除某些文件(例如*.properties)作为Henri的答案,则可以修改rebel.xml文件.

Then, if we want, we can modify the rebel.xml files if we want to exclude some files, like *.properties, as Henri's answer.

就是这样!

推荐答案

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

This can happen if you're using resource filtering with JRebel, as the application looks up the bean's xml in its unfiltered form from the project working directory (as per rebel.xml).

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

To resolve this, you'll need to update rebel.xml for that module, adding exclude for that particular XML file - see here.

示例

这篇关于春天无法使用PropertiesFactoryBean和PropertyPlaceholderConfigurer正确导入Maven属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆