Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Illegal group reference" #5

Open
OndraZizka opened this issue Jun 7, 2016 · 1 comment
Open

"Illegal group reference" #5

OndraZizka opened this issue Jun 7, 2016 · 1 comment

Comments

@OndraZizka
Copy link
Owner

01:28:58,382 ERROR [stderr](ServerService Thread Pool -- 76) ERROR when parsing programovani/java/howto-spring-reading_properties_file.texy:

java.lang.IllegalArgumentException: Illegal group reference 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) java.lang.IllegalArgumentException: Illegal group reference 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.openjdkregex.Matcher.appendReplacement(Matcher.java:725) 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.modules.HtmlOutputModule.postProcess(HtmlOutputModule.java:158) 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.modules.HtmlOutputModule.access$100(HtmlOutputModule.java:29) 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.modules.HtmlOutputModule$1.onEvent(HtmlOutputModule.java:100) 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.modules.HtmlOutputModule$1.onEvent(HtmlOutputModule.java:96) 01:28:58,383 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.JTexy.invokeNormalHandlers(JTexy.java:350) 01:28:58,384 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.JTexy.stringToHtml(JTexy.java:308) 01:28:58,384 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.JTexy.process(JTexy.java:250) 01:28:58,384 ERROR [stderr](ServerService Thread Pool -- 76) at cz.dynawest.jtexy.JTexy.process(JTexy.java:210)

@OndraZizka
Copy link
Owner Author


How to read properties file in Spring Framework
***********************************************

I've had a problem with reading `.properties` file in Spring Framework.
I needed to inject it into the iBatis' `SqlMapConfig.xml`:


/--code xml .[brush:]
  <!-- iBatis -->
  <bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="sqlMapClientProperties" value="file:conf/${profile}/nastaveni.properties" />
    <property name="configLocation" value="ibatis-maps/SqlMapConfig2.xml"/>
  </bean>
  <alias alias="iBatis" name="sqlMap"/>
\--



But iBatis kept complaining that the properties defined in the file were not resolved.
Better said, it behaved like the actual value was the property name, thus the code

/--code xml .[brush:]
  <transactionManager type="JDBC">
    <dataSource type="SIMPLE">
      <property name="JDBC.Driver" value="${jdbc.driver}"/>
\--


gave me a `ClassNotFoundException` for the class `jdbc.driver`.

What actually happened was clear when I made a test bean with a property of type `java.lang.Properties`.
Spring takes the file path "file:conf/${profile}/nastaveni.properties" as a Properties string definition
and provides iBatis a `Properties` object with a single property: `file = conf/release/nastaveni.properties`.

The solution is to use the `SqlMapClientFactoryBean`:

/--code xml .[brush:]
  <!-- iBatis -->
  <bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="sqlMapClientProperties">
      <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="location" value="file:conf/${profile}/nastaveni.properties"/>
      </bean>
    </property>
    <property name="configLocation" value="ibatis-maps/SqlMapConfig2.xml"/>
  </bean>
\--

Of course, this is a trivial think, but not much well documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant