搭建springmvc4 spring4 hibernate4整合框架tomcat用啥版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建springmvc4 spring4 hibernate4整合框架tomcat用啥版本相关的知识,希望对你有一定的参考价值。

目前最好的java-web编程环境:

spring too suit + tomcat9.0 + jdk1.8.0

可以添加hibernate 4框架,只需要添加hibernate相关jar以及在xml进行相关配置既可以了

如我的spring+hibernate的viewspace-xml(不是web.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:aop="http://www.springframework.org/schema/aop"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee"
 xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 <!-- <context:component-scan base-package="package_name"/> -->
 <context:component-scan base-package="org.lee" />
 <mvc:annotation-driven />
 <!-- 注解实现日记记录 -->
 <aop:aspectj-autoproxy />

 <bean
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/view/" />   <!-- path before request -->
  <property name="suffix" value=".jsp" />  <!-- suffix -->
 </bean>

 <!-- 国际化 -->
 <bean id="messageSource"
  class="org.springframework.context.support.ResourceBundleMessageSource">
  <property name="basenames" value="i18n.message"></property>
  <property name="defaultEncoding" value="UTF-8" />
 </bean>
 <!-- 基于Session的国际化配置 -->
 <bean id="localeResolver"
  class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean>
 <!-- 动态语言切换 -->
 <bean id="localeChangeInterceptor"
  class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
  <property name="paramName" value="locale" />
 </bean>

 <!-- 静态资源访问 -->
 <mvc:resources location="/My97DatePicker/" mapping="/My97DatePicker/**" />
 <mvc:resources location="/static/lib/" mapping="/static/lib/**" />
 <mvc:resources location="/static/css/" mapping="/static/css/**" />
 <mvc:resources location="/static/assets/" mapping="/static/assets/**" />
 <mvc:resources location="/static/js/" mapping="/static/js/**" />
 <mvc:resources location="/static/js/jqprint/" mapping="/static/js/jqprint/**" />
 <mvc:resources location="/static/bootstrap-3.3.5-dist/css/"
  mapping="/static/bootstrap-3.3.5-dist/css/**" />
 <mvc:resources location="/static/bootstrap-3.3.5-dist/js/"
  mapping="/static/bootstrap-3.3.5-dist/js/**" />
 <mvc:resources location="/static/bootstrap-3.3.5-dist/fonts/"
  mapping="/static/bootstrap-3.3.5-dist/fonts/**" />
 <!-- Bootstrap-Multiselect -->
 <mvc:resources location="/static/bootstrap-multiselect-0.9.13/dist/css/"
  mapping="/static/bootstrap-multiselect-0.9.13/dist/css/**" />
 <mvc:resources location="/static/bootstrap-multiselect-0.9.13/dist/js/"
  mapping="/static/bootstrap-multiselect-0.9.13/dist/js/**" />
 <mvc:resources location="/static/bootstrap-multiselect-0.9.13/dist/less/"
  mapping="/static/bootstrap-multiselect-0.9.13/dist/less/**" />
 <mvc:resources location="/static/bootstrap-multiselect-0.9.13/docs/css/"
  mapping="/static/bootstrap-multiselect-0.9.13/docs/css/**" />
 <mvc:resources location="/static/bootstrap-multiselect-0.9.13/docs/js/"
  mapping="/static/bootstrap-multiselect-0.9.13/docs/js/**" />
 <mvc:resources location="/static/bootstrap-multiselect-0.9.13/docs/less/"
  mapping="/static/bootstrap-multiselect-0.9.13/docs/less/**" />

 <!-- JSR 303 Validator -->
 <bean id="validator"
  class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
  <property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
  <property name="validationMessageSource" ref="messageSource" />
 </bean>
 <mvc:annotation-driven validator="validator" />
 <!-- 数据库配置 -->
 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
  init-method="init" destroy-method="close">
  <!-- mysql数据库配置 -->
  <property name="url"
   value="jdbc:mysql://localhost:3306/apj?useUnicode=true&amp;characterEncoding=utf-8" />
  <property name="username" value="root" />
  <property name="password" value="123456" />
 </bean>

 <!-- 配置jdbcTemplate -->
 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
  abstract="false" lazy-init="false" autowire="default">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
 </bean>

 <!--配置Hibernate -->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="packagesToScan" value="org.lee.model"></property>
  <property name="hibernateProperties">
   <props>
    <!-- 方言 -->
    <prop key="dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <!-- 控制台显示SQL -->
    <prop key="show_sql">true</prop>
    <!-- 自动更新表结构 -->
    <prop key="hbm2ddl.auto">update</prop>
   </props>
  </property>
 </bean>
 
 
 <!--配置Hibernate事务 -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>
 <tx:annotation-driven transaction-manager="transactionManager" />
 <!-- 考题管理的ajax相关配置 -->
 <bean
  class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  <property name="messageConverters">
   <list>
    <ref bean="mappingJackson2HttpMessageConverter" />
   </list>
  </property>
 </bean>
 <bean id="mappingJackson2HttpMessageConverter"
  class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  <property name="supportedMediaTypes">
   <list>
    <value>application/json;charset=UTF-8</value>
    <value>text/html;charset=UTF-8</value>
    <value>text/json;charset=UTF-8</value>
   </list>
  </property>
 </bean>
 <!-- 上传 -->
 <bean id="multipartResolver"
  class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

 <!-- 登录权限 -->
 <mvc:interceptors>
  <mvc:interceptor>
   <mvc:mapping path="/**" />
   <mvc:exclude-mapping path="/login" />
   <mvc:exclude-mapping path="/logout" />
   <mvc:exclude-mapping path="/static" />
   <bean class="org.lee.Interceptor.LoginInterceptor"></bean>
  </mvc:interceptor>
 </mvc:interceptors>

</beans>

参考技术A sts自带的就可以了

Spring+SpringMvc+Mybatis框架集成搭建教程

一、背景

  最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis , 以下简称SSM)框架的搭建的经历,所以在自己搭建SSM框架集成的时候,出现了这样或者那样的问题,很是苦恼,网络上又没有很详细的讲解以及搭建的教程。闲来无事,我就利用空闲时间来写这样一个教程和搭建步骤,来帮助那些有问题的小伙伴,让你从此SSM搭建不再有问题。

二、教程目录

 

  1.Spring+SpringMVC+Mybatis框架集成搭建教程一(项目创建)

 

  2.Spring+SpringMVC+Mybatis框架集成搭建教程二(依赖配置及框架整合)

 

  3.Spring+SpringMVC+Mybatis框架集成搭建教程三(框架整合测试程序开发)

 

  4.Spring+SpringMVC+Mybatis框架集成搭建教程四(项目部署及测试)

 

  5.Spring+SpringMVC+Mybatis框架集成搭建教程五(项目源码发布到GitHub)

以上是关于搭建springmvc4 spring4 hibernate4整合框架tomcat用啥版本的主要内容,如果未能解决你的问题,请参考以下文章

搭建springmvc4 spring4 hibernate4整合框架tomcat用啥版本

SpringMVC4+Spring4+Hibernate4框架整合

Mybatis3+Spring4+SpringMVC4 整合

Spring4.2.6+SpringMVC4.2.6+MyBatis3.4.0 整合

Maven搭建SpringMVC+Mybatis项目详解

Maven搭建SpringMVC+Mybatis项目详解