基本步骤:
1、 配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!--如果此处没有配置加载spring的配置,那么需要applicationContext.xml放在WEB-INF/下面
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<!-- 设置Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- spring mvc -->
<servlet>
<servlet-name>springmvc_annotation</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc_annotation</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
2、配置springmvc_annotation-servlet.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- ①:对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.annotation"/>
<!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
需要注意该配置文件中的 ① 处,该处跟applicationContext.xml中的1处,前者不能包含后者,否则会报错找不到sessionFactory,并且事务会失效。
3、配置applicationContext.xml
<?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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
default-autowire="byName" default-lazy-init="true">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
<property name="packagesToScan" value="com.founder"/>
</bean>
<!-- Support @Transactional tag -->
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!--1 扫描dao和service -->
<context:component-scan base-package="com.founder">
<context:include-filter type="regex" expression="com\.founder\.jbpm\.dao\..*"/>
<context:include-filter type="regex" expression="com\.founder\.jbpm\.service\..*"/>
</context:component-scan>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/xxx" />
<property name="username" value="xxx" />
<property name="password" value="xxx" />
</bean>
</beans>
分享到:
相关推荐
使用spring+mvc+hibernate集成redis缓存,如有需要详细使用阅读内容可以访问我的博客来查看http://blog.csdn.net/wohuozheng?ref=toolbar
spring mvc hibernate集成 基础框架 c3p0 oracle
NULL 博文链接:https://xly1981.iteye.com/blog/1897539
新SSH(spring、spring mvc、hibernate)框架结构的java web案例实践
spring 、 Spring MVC 、 Hibernate 4.x 整合案例 增删查改的封装,,里面是代码包括简单的框架搭建,只需下载后就可以允许,,正在对分页查询进行封装
Spring4 MVC Hibernate4集成,使用Annotation,封装dao层和service层。 环境: spring 4.0.3.RELEASE hibernate 4.3.5.Final mysql 5.1.29
Spring4.0.3,Hibernate4.3.5,mysql。 需要创建users表 DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `age` int(11) DEFAULT NULL, `nice_name` varchar(32) ...
SSH框架整合(spring+spring mvc+hibernate+bootstrap+maven)开发学生籍贯后台管理系统
hibernate-4.3.5 与Spring(Spring MVC4.0.4)注解方式集成 样例源码
虚拟ID介绍jVoiD 是一种开源的可扩展电子商务架构,适用于使用 J2EE、Spring MVC、带有 OAUTH2 的 Spring Security、Hibernate、Bootstrap/AngularUI、AngularJS,可以在 TomCat 或 JBoss 服务器中运行。入门先决...
原本是在eclipse下搭的,后来学习IDEA,又转到IDEA搭建的hibernate+Spring+SpringMVC架构实现增删改查等功能,和大家一起学习进步,不喜勿喷哦
Hibernate OGM redis项目与Spring MVC集成.zip
spring增强性mvc hibernate dao 操作(一个basedao全部搞定) 两种配置:oracle mysql,切换数据库只要把SessionFactory的配置文件改成对应就可以了 c3p0配置:mysql调试通过,oracle由于存在问题,未配置 spring...
4、Hibernate集成二级缓存框架Ehcache。 5、数据库是MySQL、Oracle和SQL Server,Hibernate的Dialect可使程序移植到其他数据库。 6、采用开源的互动地图Javascript库Leaflet,处理自定义在线地图。 7、采用Google ...
spring mvc + hibernate集成实现,包括ajax,文件上传,拦截器等
开发平台:myeclipse10 ,tomcat7 ,mysql project 描述:这是一个学习spring3.2+hibernate4框架集成的样例,用springMVC实现控制!前端用Extjs实现。 备:本程序仅用作学习交流! 联系邮箱:ychzbo@yeah.net
spring4+springmvc+hibernate3 demo,前端jsp,能正常运行,包含数据库person.sql,适合初学者学习,大家共同进步!
Spring4MVC+Hibernate4+Freemarker+Ehcache+EasyUi整合,里面包含数据库,数据库使用的是Mysql
基于SpringMVC以及Spring,Hibernate的非注解入门小demo