[英]configuring db properties in servlet-context and spring-security xml files in spring
DB Configuration : 数据库配置:
servlet-context.xml servlet-context.xml
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
spring-security.xml spring-security.xml
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://localhost:3306/rni" />
<beans:property name="username" value="root" />
<beans:property name="password" value="root" />
</beans:bean>
In servlet-context.xml i configured database properties from properties file 在servlet-context.xml中,我从属性文件配置了数据库属性
Same properties i need to use in spring-security.xml 我需要在spring-security.xml中使用的相同属性
please tell me the way how to approach? 请告诉我该如何处理?
Since both are managed by spring's single container, you can use the EL in spring-security.xml as well 由于两者都由spring的单个容器管理,因此您也可以在spring-security.xml中使用EL
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://localhost:3306/rni" />
<beans:property name="username" value="${jdbc.username}" />
<beans:property name="password" value="${jdbc.password}" />
</beans:bean>
However I'm not sure why you need two datasources. 但是我不确定为什么需要两个数据源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.