spring-springmvc-hibernate整合之配置文件
2017-05-10 20:53
477 查看
1.web.xml文件:
2.spring-mvc配置文件:
3.spring-hibernate配置文件:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <!--spring mvc--> <servlet> <servlet-name>stuManagement</servlet-name> <init-param> <param-name>contextConfigLocation</param-name> <!--配置文件名称及路径--> <param-value>classpath:config/springmvc.xml</param-value> </init-param> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>stuManagement</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!----> <!--spring-hibernate--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <!--配置文件名称及路径--> <param-value>classpath:config/spring-hibernate.xml</param-value> </context-param> <!----> <!--字符编码--> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!----> </web-app>
2.spring-mvc配置文件:
依赖的jar包: 1. spring-framwork.jar ,commons-log.jar ,commons-dbcp.jar ,commons-pool.jar 2. com.fasterxml.jackon.annotations.jar ,jackon-core.jar ,jackon-databind.jar
<?xml version="1.0" encoding="UTF-8"?> <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" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <mvc:annotation-driven/> <!--控制器(bean)--> <context:component-scan base-package="Controller"/> <!----> <!--拦截器--> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/Management/*"/> <!-- 管理员登录拦截 --> <bean class="Interceptor.UserInterceptor"></bean> </mvc:interceptor> </mvc:interceptors> <!--json数据转换器--> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> <!----> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/View/"/> <property name="suffix" value=".jsp"/> </bean> <!----> </beans>
3.spring-hibernate配置文件:
依赖的jar包: 1. hibernate-required.jar ,mysql-connection-java.jar
<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" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--bean--> <context:component-scan base-package="Model"/> <!----> <!--注入session factory--> <!--指定JDBC要连接的数据库--> <bean id="DataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/数据库名"/> <property name="username" value="账户名"/> <property name="password" value="密码"/> </bean> <!----> <!--配置hibernate--> <bean id="SessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="DataSource"/> <!--配置hibernate关于数据库操作--> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <!----> </bean> <!----> <!----> <!--配置事务管理机制--> <tx:annotation-driven/> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="SessionFactory"/> </bean> <!----> </beans>
相关文章推荐
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- Hibernate与Spring整合,配置文件applicationContext.xml
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- spring 整合hibernate的配置文件的两种方式
- Spring 整合 Hibernate 的一处简化引入PO映射文件配置
- Spring3.0、Hibernate3.0、Struts2整合文件配置
- spring整合hibernate配置文件
- 基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)
- spring整合hibernate配置文件
- ssh框架中spring整合hibernate的配置文件模板(带详细注释)
- Spring与Hibernate配置文件整合
- Struts,Hibernate,Spring整合的重点在于配置文件
- spring整合hibernate步骤及配置文件
- Spring整合Hibernate开发 - 使用事务管理器操作数据库 - 主配置文件
- struts+hibernate+spring整合的文件配置详解
- SSH:SSH(Struts1 + Spring + hibernate)整合之配置文件
- s2sh整合中hibernate两种配置方式中spring配置文件中的不同
- Hibernate与Spring整合,配置文件applicationContext.xml
- spring hibernate整合时配置文件的事务部分(spring管理事务)
- spring和hibernate整合、spring和jdbc整合 配置文件