spring-springmvc-hibernate整合之配置文件
来源:互联网 发布:oracle数据库表空间 编辑:程序博客网 时间:2024/05/20 15:41
1.web.xml文件:
<?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.jar2. 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>
1 0
- spring-springmvc-hibernate整合之配置文件
- Spring+springmvc+hibernate+redis整合配置文件
- Spring+SpringMVC整合----配置文件
- spring整合hibernate配置文件
- spring整合hibernate配置文件
- spring整合hibernate配置文件
- spring整合hibernate配置文件
- Spring整合hibernate配置文件
- spring整合hibernate配置文件
- spring整合hibernate配置文件
- spring整合hibernate配置文件
- spring+springMVC+Hibernate配置文件
- SpringMVC+Spring+Hibernate整合
- SpringMVC整合Spring、Hibernate
- Spring-SpringMVC-Hibernate整合
- SpringMVC+Spring+Hibernate整合
- SpringMVC+Spring+hibernate整合
- springmvc-spring-hibernate整合
- zTree异步加载数据,默认展开全部节点
- linux进程通信之共享内存高级议题
- Effective Java 创建和销毁对象(1~7)
- 使用 Spring 2.5 基于注解驱动的 Spring MVC
- Maven--初使用时的配置
- spring-springmvc-hibernate整合之配置文件
- 博弈
- SSH框架 DAO注入失败 ---总结
- 【个人笔记重点,不作为参考】主题:windows git安装与cmd全局设置
- jQuery常用事件的API
- 地道美语听力播客 3
- 贴瓷砖
- poj 3087 Shuffle'm Up
- Qt如何不让父窗口的颜色影响子窗口