1,在配置文件中使用占位符“$”,可以使用PropertyPlaceholderConfigurer,
如: <bean id="config" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:config-hibernate.properties</value>
</list>
</property>
</bean>
在src下有一个配置文件:config-hibernate.properties。内容:
jndiName=datasource
resourceRef=true
java.naming.provider.url=t3\://localhost\:7001
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
hibernate.dialect=org.hibernate.dialect.OracleDialect
hibernate.query.substitutions=true 'T', false 'F'
hibernate.show_sql=true
2,然后就可以在配置文件中通过占位符来利用了
如: <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>${jndiName}</value>
</property>
<property name="resourceRef">
<value>${resourceRef}</value>
</property>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">${java.naming.provider.url}</prop>
<prop key="java.naming.factory.initial">${java.naming.factory.initial}</prop>
</props>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.query.substitutions">
${hibernate.query.substitutions}
</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/entity/Demo.hbm.xml</value>
</list>
</property>
</bean>
如: <bean id="config" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:config-hibernate.properties</value>
</list>
</property>
</bean>
在src下有一个配置文件:config-hibernate.properties。内容:
jndiName=datasource
resourceRef=true
java.naming.provider.url=t3\://localhost\:7001
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
hibernate.dialect=org.hibernate.dialect.OracleDialect
hibernate.query.substitutions=true 'T', false 'F'
hibernate.show_sql=true
2,然后就可以在配置文件中通过占位符来利用了
如: <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>${jndiName}</value>
</property>
<property name="resourceRef">
<value>${resourceRef}</value>
</property>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">${java.naming.provider.url}</prop>
<prop key="java.naming.factory.initial">${java.naming.factory.initial}</prop>
</props>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.query.substitutions">
${hibernate.query.substitutions}
</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/entity/Demo.hbm.xml</value>
</list>
</property>
</bean>