SpringMVC下的基本配置


application.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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-2.5.xsd  
    http://www.springframework.org/schema/aop   
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
      http://www.springframework.org/schema/context     
      http://www.springframework.org/schema/context/spring-context-2.5.xsd
      http://www.springframework.org/schema/mvc   
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
    ">

    <!-- 事务bean -->
    <bean id="txManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 链接点 -->
    <tx:advice id="txAvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="find*" propagation="NOT_SUPPORTED"
                read-only="true" />
            <tx:method name="paging" propagation="NOT_SUPPORTED"
                read-only="true" />
            <tx:method name="q*" propagation="NOT_SUPPORTED" read-only="true" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="keep*" propagation="REQUIRED" />
            <tx:method name="d*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="upd*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut expression="execution(* com.houpusvse.oa.service.impl.*.*(..))"
            id="myPoin" />
        <aop:advisor advice-ref="txAvice" pointcut-ref="myPoin" />
    </aop:config>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver">
        </property>
        <property name="url" value="jdbc:mysql://localhost:3306/oa"></property>
        <property name="username" value="root"></property>
        <property name="password" value="mysql"></property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
            </props>
        </property>
        <property name="annotatedClasses">
            <list>
                <!-- 实体部分由Hibernate方向工程自动生成 -->
                <value>com.houpusvse.oa.entity.Module</value>
                <value>com.houpusvse.oa.entity.Pware</value>
                <value>com.houpusvse.oa.entity.Premiums</value>
                <value>com.houpusvse.oa.entity.Carpurchase</value>
                <value>com.houpusvse.oa.entity.Structure</value>
                <value>com.houpusvse.oa.entity.Carbrands</value>
                <value>com.houpusvse.oa.entity.Groups</value>
                <value>com.houpusvse.oa.entity.Maction</value>
                <value>com.houpusvse.oa.entity.Purchase</value>
                <value>com.houpusvse.oa.entity.Grule</value>
                <value>com.houpusvse.oa.entity.Cssdetails</value>
                <value>com.houpusvse.oa.entity.Carsellservice</value>
                <value>com.houpusvse.oa.entity.Depot</value>
                <value>com.houpusvse.oa.entity.Carsnries</value>
                <value>com.houpusvse.oa.entity.Carware</value>
                <value>com.houpusvse.oa.entity.Ppurchase</value>
                <value>com.houpusvse.oa.entity.Jtitle</value>
                <value>com.houpusvse.oa.entity.Carwaredetails</value>
                <value>com.houpusvse.oa.entity.Client</value>
                <value>com.houpusvse.oa.entity.Pwdetails</value>
                <value>com.houpusvse.oa.entity.Post</value>
                <value>com.houpusvse.oa.entity.Usergroup</value>
                <value>com.houpusvse.oa.entity.Psellout</value>
                <value>com.houpusvse.oa.entity.Users</value>
                <value>com.houpusvse.oa.entity.Carout</value>
                <value>com.houpusvse.oa.entity.Pcarout</value>
            </list>
        </property>
    </bean>
    <!-- 注解 -->
    <mvc:annotation-driven />
    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.houpusvse.oa"></context:component-scan>

</beans>

spring-servlet.xml

<!-- 包含开启注解,json类型转换,乱码,视图控制器,满足一般开发所需 -->
<?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"
    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-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/util   
           http://www.springframework.org/schema/util/spring-util-3.0.xsd  
           http://www.springframework.org/schema/mvc   
           http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    
    <context:component-scan base-package="com.houpusvse.oa.controller" />
    <!-- ViewResolver -->
    <bean
        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>

    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <util:list id="beanList">
                <ref bean="mappingJacksonHttpMessageConverter" />
            </util:list>
        </property>
    </bean>
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    </bean>
    <context:annotation-config/>  
    
    
</beans>

基本就是这样,忘记的时候可以拿来用用........

时间: 2024-08-02 11:09:08

SpringMVC下的基本配置的相关文章

1.Maven+SpringMVC+Eclipse软件安装配置,Maven报插件错误,Eclipse总是卡死的解决办法,导入一个maven工程后 一直显示importing maven project

 使用Maven+SpringMVC+Eclipse软件安装配置过程中的问题: 1.Eclipse总是卡死的解决办法: 一:内存不足所以会卡死,配置一下eclipse.ini修改这几个值就好了-XX:MaxPermSize=768m-Xms1024m-Xmx3072m搜索 二:修改window->preferences --- > JAVA->Edittor->Hovers,将右侧所有复选框清空. 2.因为eclipse上一次未正常关闭,导致启动卡死,错误日志为: [plain

(转)springMVC+mybatis+ehcache详细配置

一. Mybatis+Ehcache配置 为了提高MyBatis的性能,有时候我们需要加入缓存支持,目前用的比较多的缓存莫过于ehcache缓存了,ehcache性能强大,而且位各种应用都提供了解决方案,在此我们主要是做查询缓存,提高查询的效率. 整合MyBatis和ehcache需要的jar包如下: ehcache-core-2.4.4.jar mybatis-ehcache-1.0.0.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.2.jar 资源已上传

springMVC+mybatis+ehcache详细配置

一. Mybatis+Ehcache配置 为了提高MyBatis的性能,有时候我们需要加入缓存支持,目前用的比较多的缓存莫过于ehcache缓存了,ehcache性能强大,而且位各种应用都提供了解决方案,在此我们主要是做查询缓存,提高查询的效率. 整合MyBatis和ehcache需要的jar包如下: ehcache-core-2.4.4.jar mybatis-ehcache-1.0.0.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.2.jar 资源已上传

基于SpringMVC下的Rest服务框架搭建【1、集成Swagger】

基于SpringMVC下的Rest服务框架搭建[1.集成Swagger] 1.需求背景 SpringMVC本身就可以开发出基于rest风格的服务,通过简单的配置,即可快速开发出一个可供客户端调用的rest服务,通常这些服务要不就是用于手机app的开发,要不就是提供给第三方开发者使用,不管哪种情况,你都需要提供详细的说明给别人,而Swagger就是为这种情况而生的,通过在接口上的注解,生成可供第三方模拟测试和阅读的接口列表,既美观又使用,真是行走江湖之必备良药. [XmPlatform原创,转载的

springmvc下的基于token的防重复提交

问题描述: 现在的网站在注册步骤中,由于后台要处理大量信息,造成响应变慢(测试机器性能差也是造成变慢的一个因素),在前端页面提交信息之前,等待后端响应,此时如果用户再点一次提交按钮,后台会保存多份用户信息.为解决此问题,借鉴了struts2的token思路,在springmvc下实现token. 实现思路: 在springmvc配置文件中加入拦截器的配置,拦截两类请求,一类是到页面的,一类是提交表单的.当转到页面的请求到来时,生成token的名字和token值,一份放到redis缓存中,一份放传

springmvc深入学习----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.or

Centos7下安装及配置PPTP VPN

说到VPN服务,我们大家都知道,VPN是虚拟专用网络(Virtual Private Network)的缩写,VPN有多种分类方式,包括PPTP.L2TP.IPSec等,本文配置的VPN服务器是采用PPTP协议的,PPTP是在PPP协议基础上开发的一种新的增强型安全协议.当然在windows上和linux上都可以部署服务,我们今天主要介绍一下在Centos7下安装及配置PPTP VPN. 因为PPTP是基于PPP协议基础上的,因此需要系统支持PPP,使用 rpm -qa ppp 检查是否安装了P

win环境下,django+postgresql配置

先下载postgresql的python包,选择合适自己的python版本和平台32位还是64位,http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 下载win环境下postgresql接口,http://www.stickpeople.com/projects/python/win-psycopg/ 设置django settings.py DATABASES项 注:第2步如果不操作就会出现from psycopg2._psycopg import

Linux下Redis服务器安装配置

说明:操作系统:CentOS1.安装编译工具yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils  patch perl 2.安装tcl组件包(安装Redis需要tcl支持)cd /usr/local/src #进入软件包存放目录wget  http://downloads.sourceforge.net/tcl/tcl8.6.6-src.tar.gztar