What is the best solution for avoiding duplication of the database
connection string/url in "application.conf" if you want to use JPA/
Hibernate in Spring's configuration file "application-context.xml" ?
(and please do stick to the question, and avoid off-topic question
such as "why do you want to use JPA")
I mean, the problem seem to be that if you define the property with
double quotes, then these double quotes become included when Spring
are referencing the properties with PropertyPlaceholderConfigurer.
Here is an example, illustrating the configuration I mean:
Some of the content in file "[PLAY_PROJECT_HOME]/conf/
application.conf:
db.default.url="jdbc:jtds:sqlserver://URL_TO_SQL_SERVER:PORT/
DATABASE_NAME;instance=NAME_OF_SQL_INSTANCE"
...
Some of the content in file "[PLAY_PROJECT_HOME]/conf/application-
context.xml (Spring configuration file):
...
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>application.conf</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="net.sourceforge.jtds.jdbc.Driver"
p:url="${db.default.url}"
p:username="${db.default.user}"
p:password="${db.default.password}"
/>
If not using the double quotes, then I get this problem:
Expecting end of input or a comma, got ':' (if you intended ':' to be
part of the value for 'db.default.url', try enclosing the value in
double quotes, or you may be able to rename the file .properties
rather than .conf)
(
And indeed, according to the following discussion, the database url
need the double quotes:
http://groups.google.com/group/play-framework/msg/5011e0d8f88fe762
)
However, if I am using the double quotes, then it does not work with
Spring configuration.
I think the problem is that those will effectively become substituted
into the spring configuration like this:
The following part of the Spring config file:
p:url="${db.default.url}"
will becomes
p:url=""jdbc:jtds:sqlserver://URL_TO_SQL_SERVER:PORT/
DATABASE_NAME;instance=NAME_OF_SQL_INSTANCE""
(or kind of like this:
p:url="\"jdbc:jtds:sqlserver://URL_TO_SQL_SERVER:PORT/
DATABASE_NAME;instance=NAME_OF_SQL_INSTANCE\""
)
So, what would the best solution be for being able to reuse the
database url without duplication ?