how to move config xml files from WEB-INF to resources in java spring? -
i study java spring. configure spring 4+hibernate4. have done so:
hibernate-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="datasource" class="com.mchange.v2.c3p0.combopooleddatasource" destroy-method="close"> <property name="driverclass" value="com.mysql.jdbc.driver"/> <property name="jdbcurl" value="jdbc:mysql://localhost:3306/springdb?autoreconnect=true"/> <property name="user" value="pavel"/> <property name="password" value="qwerty"/> <!-- c3p0 properties refer: http://www.mchange.com/projects/c3p0/ --> <property name="acquireincrement" value="2"/> <property name="minpoolsize" value="20"/> <property name="maxpoolsize" value="50"/> <property name="maxidletime" value="600"/> </bean> <!-- hibernate session factory --> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean" p:datasource-ref="datasource"> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="packagestoscan" value="com.springapp.mvc.model"/> </bean> <bean id="hibernatesessionfactory" class="com.springapp.mvc.dao.impl.hibernatesessionfactoryimpl"> <property name="sessionfactory" ref="sessionfactory"/> </bean> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory"/> </bean> <tx:annotation-driven transaction-manager="transactionmanager"/> </beans>
and mvc-dispatcher-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.springapp.mvc"/> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/pages/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
and have structure:
and in web.xml:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>spring mvc application</display-name> <!-- definition of root spring container shared servlets , filters --> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/hibernate-config.xml</param-value> </context-param> <!-- creates spring container shared servlets , filters --> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <filter> <filter-name>hibernatefilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.opensessioninviewfilter</filter-class> <init-param> <param-name>singlesession</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernatefilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
but want create file hibernate-config.xml:
in resources
directory. but not understand how it.
move hibernate-config.xml
file resources directory , in web.xml
change param-value from
<param-value>/web-inf/hibernate-config.xml</param-value>
to
<param-value>classpath:hibernate-config.xml</param-value>
Comments
Post a Comment