Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A commonly used strategy is to define all runtime configurations in one or several *.properties files and use spring's PropertyPlaceholderConfigurer to load the values and substitute the placeholder in applicationContext.xml, read more here: <a href="https://stackoverflow.com/questions/13297157/best-ways-to-deal-with-properties-values-in-xml-file-in-spring-maven-and-eclips/13297686#13297686">Best ways to deal with properties values in XML file in Spring, Maven and Eclipses</a>.</p> <p>app.properties:</p> <pre><code># Dadabase connection settings: hibernate.connection.driver_class=org.hsqldb.jdbcDriver hibernate.connection.url=jdbc:hsqldb:file:~/something-db/somethingdb hibernate.connection.username=sa hibernate.connection.password=changeit hibernate.dialect=org.hibernate.dialect.HSQLDialect hbm2ddl.auto=update ... ... </code></pre> <p>applicationContext-dataStore.xml:</p> <pre><code>&lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;list&gt; &lt;!-- Default location inside war file --&gt; &lt;value&gt;classpath:app.properties&lt;/value&gt; &lt;!-- Environment specific location, a fixed path on deployment server --&gt; &lt;value&gt;file:///opt/my-app/conf/app.properties&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="ignoreResourceNotFound" value="true"/&gt; &lt;/bean&gt; ... ... &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${hibernate.connection.driver_class}" /&gt; &lt;property name="url" value="${hibernate.connection.url}" /&gt; &lt;property name="username" value="${hibernate.connection.username}" /&gt; &lt;property name="password" value="${hibernate.connection.password}" /&gt; &lt;/bean&gt; </code></pre> <p>One problem here is the PropertyPlaceholderConfigurer doesn't parse persistence.xml, the solution is to move all hibernate configuration into Spring's applicationContext.xml, as it is not necessary to set them in persistence.xml. read more here: <a href="https://stackoverflow.com/questions/1834954/loading-properties-in-spring-context-xml-and-persistence-xml/3979832#3979832">loading .properties in spring-context.xml and persistence.xml</a>.</p> <p>persistence.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt; &lt;persistence-unit name="JPAService" transaction-type="RESOURCE_LOCAL"/&gt; &lt;/persistence&gt; </code></pre> <p>applicationContext-datSource.xml:</p> <pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${hibernate.connection.driver_class}"/&gt; &lt;property name="url" value="${hibernate.connection.url}"/&gt; &lt;property name="username" value="${hibernate.connection.username}"/&gt; &lt;property name="password" value="${hibernate.connection.password}"/&gt; &lt;/bean&gt; ... ... &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceXmlLocation" value="classpath:./META-INF/persistence.xml"/&gt; &lt;property name="persistenceUnitName" value="JPAService"/&gt; &lt;property name="dataSource" ref="dataSource"/&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="databasePlatform" value="${hibernate.dialect}"/&gt; &lt;property name="showSql" value="true" /&gt; &lt;property name="generateDdl" value="true"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="jpaProperties"&gt; &lt;!-- set extra properties here, e.g. for Hibernate: --&gt; &lt;props&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;${hbm2ddl.auto}&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>Note that the web application need to be restarted every time you alter the configuration in /opt/my-app/conf/app.properties, in order to make changes take effect.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload