分类: J2EE2010-11-25 17:21 16667人阅读 评论(1) 收藏 举报

在公司一直没有什么机会直接折腾SSH“原生态”的SSH当今比较流行的轻量级的框架,用着公司的框架也是郁闷异常,今天没事整整原来用过的一个项目的配置,发现就算是自己曾经用过的东西,如果较长时间不返过去重新学习,许多你半熟不熟的知识就是异常陌生。下面贴上我的一些配置,暂且权当备份吧。

web.xml

作为Java web项目最为重要的配置文件,下面我们看看我的一些相关配置。

<!-- 配置Spring上下文 -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring*.xml</param-value>

</context-param>

<!-- 启动 Spring 监听器 -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!-- 编码过滤器 -->

<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>

<!-- 配置 OpenSessionInView -->

<filter>

<filter-name>hibernateOpenSessionInView</filter-name>

<filter-class>com.geek.core.dao.OpenSessionInView</filter-class>

<init-param>

<param-name>excludeSuffixs</param-name>

<param-value>js,css,jpg,gif,jpeg,mp3</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>hibernateOpenSessionInView</filter-name>

<url-pattern>*.do</url-pattern>

</filter-mapping>

<!-- 配置 Spring Servlet 分发器 -->

<servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring-action.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

Spring的相关配置文件,Hibernate也共用了Spring的配置文件

spring-action.xml

<!-- Web层Action类扫描 -->

<context:component-scan base-package="com.geek.core.web.action" />

<!-- Action类注解配置 -->

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>

<!-- 视图解析器配置 -->

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>

<property name="prefix" value="/"></property>

</bean>

spring-persistence.xml

<!-- 配置注解注入 -->

<context:annotation-config />

<!-- 持久层类所在包扫描-->

<context:component-scan base-package="com.geek.core.dao.impl" />

spring-service.xml

<!-- 配置 Service 类扫描包 -->

<context:component-scan base-package="com.geek.core.service.impl" />

spring.xml [Hibernate共用]

<!-- MySQL 数据源配置 -->

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

<property name="driverClassName"value="com.mysql.jdbc.Driver"></property>

<property name="url"value="jdbc:mysql://127.0.0.1:3306/smile"></property>

<property name="username" value="smile"></property>

<property name="password" value="smile"></property>

</bean>

<!-- Session 工厂配置 -->

<bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

<property name="dataSource"><ref bean="dataSource"></ref></property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

<prop key="hibernate.hbm2ddl.auto">update</prop>

</props>

</property>

<!-- ORM [注解] 配置实体包 -->

<property name="packagesToScan">

<list>

<value>com.geek.core.pojo</value>

</list>

</property>

</bean>

<!-- 配置事务管理器 -->

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<property name="sessionFactory" ref="sessionFactory"></property>

</bean>

<!-- 使用注解配置事务 -->

<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>

注:在配置过程中也出现了相关的错误,组要是schema引入的问题,如context和tx的引入,所以需多加注意。

<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:tx="http://www.springframework.org/schema/tx"

xmlns:context="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/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

…………

:)

Spring+Hibernate整合配置 --- 比较完整的spring、hibernate 配置的更多相关文章

  1. 使用Spring boot整合Hive,在启动Spring boot项目时,报错

    使用Spring boot整合Hive,在启动Spring boot项目时,报出异常: java.lang.NoSuchMethodError: org.eclipse.jetty.servlet.S ...

  2. 项目SpringMVC+Spring+Mybatis 整合环境搭建(2)-> 测试Spring+Mybatis 环境

    测试前期准备 第一步:创建easybuy数据库,设置utf-8格式 第二步:创建表test_tb CREATE TABLE `test_tb` ( `id` int(11) NOT NULL AUTO ...

  3. Spring与Hibernate整合,实现Hibernate事务管理

    1.所需的jar包 连接池/数据库驱动包 Hibernate相关jar Spring 核心包(5个) Spring aop 包(4个) spring-orm-3.2.5.RELEASE.jar     ...

  4. Spring Boot 整合 Freemarker,50 多行配置是怎么省略掉的?

    Spring Boot2 系列教程接近完工,最近进入修修补补阶段.Freemarker 整合貌似还没和大家聊过,因此今天把这个补充上. 已经完工的 Spring Boot2 教程,大家可以参考这里: ...

  5. spring boot整合slf4j-log日志

    原文地址:https://blog.csdn.net/u011271894/article/details/75735915 版权声明:本文为博主原创文章,未经博主允许不得转载. https://bl ...

  6. Spring Boot2 系列教程(二十四)Spring Boot 整合 Jpa

    Spring Boot 中的数据持久化方案前面给大伙介绍了两种了,一个是 JdbcTemplate,还有一个 MyBatis,JdbcTemplate 配置简单,使用也简单,但是功能也非常有限,MyB ...

  7. Spring Boot2 系列教程(二十五)Spring Boot 整合 Jpa 多数据源

    本文是 Spring Boot 整合数据持久化方案的最后一篇,主要和大伙来聊聊 Spring Boot 整合 Jpa 多数据源问题.在 Spring Boot 整合JbdcTemplate 多数据源. ...

  8. Spring Cloud实战 | 第九篇:Spring Cloud整合Spring Security OAuth2认证服务器统一认证自定义异常处理

    本文完整代码下载点击 一. 前言 相信了解过我或者看过我之前的系列文章应该多少知道点我写这些文章包括创建 有来商城youlai-mall 这个项目的目的,想给那些真的想提升自己或者迷茫的人(包括自己- ...

  9. Spring Cloud实战 | 第十篇 :Spring Cloud + Seata 1.4.1 + Nacos1.4.0 整合实现微服务架构中逃不掉的话题分布式事务

    Seata分布式事务在线体验地址:https://www.youlai.store 本篇完整源码地址:https://github.com/hxrui/youlai-mall 有想加入开源项目开发的童 ...

随机推荐

  1. Spotlight on Unix/Mysql安装使用详解

    Spotlight on Unix安装使用详解  1.远程连接linux服务器,查看系统是否已经安装sysstat包,如果没有的话,按照以下方法安装sysstat. (1)检查Linux是否安装sys ...

  2. 关于git 远程仓库账户密码错误的问题

    主要是电脑凭证把第一次输入的账户密码记录了下来,在控制面板->用户账户->凭据管理器里, 选择windows凭证, 你会找到git:凭据,直接删掉或者更改都可以! 对应的Git的凭证,删除 ...

  3. 洛谷3834 hdu2665主席树模板,动态查询区间第k小

    题目链接:https://www.luogu.com.cn/problem/P3834 对于区间查询第k小的问题,在区间数量达到5e5的时候是难以用朴素数据结构实现的,这时候主席树就应运而生了,主席树 ...

  4. windows10 64位 安装mysql服务端 并使用navicat客户端链接 掉的一堆坑

    1.目的 安装mysql服务端 并使用navicat客户端链接 2.过程 1)下载mysql服务端 下载过程(参考https://blog.csdn.net/youxianzide/article/d ...

  5. css 重排与重绘

    css 重绘与重排 我们要知道当浏览器下载完页面的所有资源后,就会开始解析源代码. HTML 会被解析成 DOM Tree,Css 则会被渲染成 CSSOM Tree,最后它们会附加到一起,形成渲染树 ...

  6. Oracle 10g客户端的安装和配置

    1.双击Oracle11g_database安装目录下的Setup.exe. 2.选择“基本安装”,设置“安装位置”,填写“数据库名”和“口令”,点击“下一步”. 3.点击“下一步”. 4.一般会出现 ...

  7. 模块 configparser 配置文件生成修改

    此模块用于生成和修改常见配置文档 1.来看一个好多软件的常见配置文件格式如下***.ini [DEFAULT] ServerAliveInterval = 45 Compression = yes C ...

  8. 数据源管理 | 基于JDBC模式,适配和管理动态数据源

    本文源码:GitHub·点这里 || GitEE·点这里 一.关系型数据源 1.动态数据源 动态管理数据源的基本功能:数据源加载,容器维护,持久化管理. 2.关系型数据库 不同厂商的关系型数据库,提供 ...

  9. 微信小程序生成带参数的二维码(小程序码)独家asp.net的服务端c#完整代码

    一)我先用的小程序端的wx.request去调用API,发现竟然是一个坑! wx.request({ url: 'https://api.weixin.qq.com/wxa/getwxacodeunl ...

  10. jvm的类加载机制总结

    类的加载机制分为如下三个阶段:加载,连接,初始化.其中连接又分为三个小阶段:验证,准备,解析. 加载阶段 将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后再堆内创 ...