Cannot import correctly maven properties with PropertiesFactoryBean and PropertyPlaceholderConfigurer in spring

574 views Asked by At

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

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

This application.version comes from maven pom.xml:

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

The bean is:

<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>

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

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

Thanks in advance.

UPDATE:

This how I generate the 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>

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.

Would be that correct?

Thanks.

UPDATE WITH THE SOLUTION:

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>

To create the rebel.xml:

mvn jrebel:generate

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

And that's it!

1

There are 1 answers

4
Henri Viik On BEST ANSWER

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).

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

Example