以实例讲解Spring+Spring MVC+Hibernate框架搭建步骤:
一、配置web.
<?二、配置applicationContext. <?version="1.0" encoding="UTF-8"?> <beans "http://www.springframework.org/schema/beans" "http://www.w3.org/2001/ "http://www.springframework.org/schema/p" "http://www.springframework.org/schema/tx" "http://www.springframework.org/schema/aop" "http://www.springframework.org/schema/context" 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-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-init-method="init"> <!-- 引入jdbc配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> </bean> <!-- 配置SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="show_sql">true</prop> <prop key="format_sql">true</prop> </props> </property> <property name="packagesToScan"> <list> <value>com.xieke.test.entity</value><!-- 扫描实体类 --> </list> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 配置事务管理器,使用**声明式事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <!-- 配置事务属性 --> <property name="transactionAttributes"> <props> <!-- PROPAGATION_REQUIRED:支持当前事务,如果当前没有事务,则新建一个事务 --> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>*ServiceImpl</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean> </beans> <?三、配置dispatcher-servlet. <?version="1.0" encoding="UTF-8"?> <beans "http://www.springframework.org/schema/beans" "http://www.springframework.org/schema/aop" "http://www.springframework.org/schema/context" "http://www.springframework.org/schema/mvc" "http://www.springframework.org/schema/tx" "http://www.w3.org/2001/ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 自动扫描注解组件并且自动注入 --> <context:component-scan base-package="com.xieke.test" /> <!-- 开启注解 --> <mvc:annotation-driven /> <!-- 激活默认的静态资源处理器 --> <mvc:default-servlet-handler/> <!-- 配置spring mvc的默认首页 --> <mvc:view-controller path="/" view-name="redirect:/car/index" /> <!--视图解析器--> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> <? <bean id="viewResolver" > <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans> 原标题:搭建基于全注解的Spring+Spring MVC+Hibernate框架关键词:Spring
二、配置applicationContext.
<?三、配置dispatcher-servlet. <?version="1.0" encoding="UTF-8"?> <beans "http://www.springframework.org/schema/beans" "http://www.springframework.org/schema/aop" "http://www.springframework.org/schema/context" "http://www.springframework.org/schema/mvc" "http://www.springframework.org/schema/tx" "http://www.w3.org/2001/ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 自动扫描注解组件并且自动注入 --> <context:component-scan base-package="com.xieke.test" /> <!-- 开启注解 --> <mvc:annotation-driven /> <!-- 激活默认的静态资源处理器 --> <mvc:default-servlet-handler/> <!-- 配置spring mvc的默认首页 --> <mvc:view-controller path="/" view-name="redirect:/car/index" /> <!--视图解析器--> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> <? <bean id="viewResolver" > <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans> 原标题:搭建基于全注解的Spring+Spring MVC+Hibernate框架关键词:Spring
三、配置dispatcher-servlet.
<? <bean id="viewResolver" > <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans> 原标题:搭建基于全注解的Spring+Spring MVC+Hibernate框架关键词:Spring
<bean id="viewResolver" > <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans>
原标题:搭建基于全注解的Spring+Spring MVC+Hibernate框架
关键词:Spring