你的位置:首页 > ASP.net教程

[ASP.net教程]SpringMVC+Maven开发框架搭建


文章只是利用maven将springMVC的框架搭建进行记录。

1.maven项目中pom. 收藏代码

  1. <project "http://maven.apache.org/POM/4.0.0" "http://www.w3.org/2001/
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>spring-web</groupId>  
  5.     <artifactId>Spring-Web-Maven</artifactId>  
  6.     <packaging>war</packaging>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <name>Spring-Web-Maven Maven Webapp</name>  
  9.     <url>http://maven.apache.org</url>  
  10.   
  11.     <dependencies>  
  12.         <dependency>  
  13.             <groupId>junit</groupId>  
  14.             <artifactId>junit</artifactId>  
  15.             <version>3.8.1</version>  
  16.             <scope>test</scope>  
  17.         </dependency>  
  18.   
  19.         <dependency>  
  20.             <groupId>javax.servlet.jsp</groupId>  
  21.             <artifactId>jsp-api</artifactId>  
  22.             <version>2.2.1-b03</version>  
  23.         </dependency>  
  24.         <dependency>  
  25.             <groupId>javax.servlet</groupId>  
  26.             <artifactId>servlet-api</artifactId>  
  27.             <version>3.0-alpha-1</version>  
  28.         </dependency>  
  29.         <dependency>  
  30.             <groupId>javax.servlet</groupId>  
  31.             <artifactId>jstl</artifactId>  
  32.             <version>1.2</version>  
  33.         </dependency>  
  34.   
  35.         <!-- Spring -->  
  36.         <dependency>  
  37.             <groupId>org.springframework</groupId>  
  38.             <artifactId>spring-orm</artifactId>  
  39.             <version>4.1.4.RELEASE</version>  
  40.         </dependency>  
  41.   
  42.         <!-- Spring MVC -->  
  43.         <dependency>  
  44.             <groupId>org.springframework</groupId>  
  45.             <artifactId>spring-webmvc</artifactId>  
  46.             <version>4.1.4.RELEASE</version>  
  47.         </dependency>  
  48.   
  49.         <!-- aspectJ -->  
  50.         <dependency>  
  51.             <groupId>org.aspectj</groupId>  
  52.             <artifactId>aspectjweaver</artifactId>  
  53.             <version>1.8.4</version>  
  54.         </dependency>  
  55.   
  56.         <dependency>  
  57.             <groupId>commons-fileupload</groupId>  
  58.             <artifactId>commons-fileupload</artifactId>  
  59.             <version>1.2.2</version>  
  60.         </dependency>  
  61.         <dependency>  
  62.             <groupId>commons-io</groupId>  
  63.             <artifactId>commons-io</artifactId>  
  64.             <version>2.1</version>  
  65.         </dependency>  
  66.           
  67.     </dependencies>  
  68.   
  69.     <build>  
  70.         <finalName>Spring-Web-Maven</finalName>  
  71.     </build>  
  72. </project>  

<project 

 2、web. 收藏代码

  1. <?version="1.0" encoding="UTF-8"?>  
  2. <web-app "http://www.w3.org/2001/
  3.     "http://java.sun.com/"http://java.sun.com/
  4.     xsi:schemaLocation="http://java.sun.com/
  5.     id="WebApp_ID" version="2.5">  
  6.   
  7.     <display-name>Spring-Web-Maven</display-name>  
  8.   
  9.     <welcome-file-list>  
  10.         <welcome-file>view/index.jsp</welcome-file>  
  11.     </welcome-file-list>  
  12.   
  13.     <!-- 加载所有的配置文件 -->  
  14.     <context-param>  
  15.         <param-name>contextConfigLocation</param-name>  
  16.         <param-value>classpath*:applicationContext-*.</param-value>  
  17.     </context-param>  
  18.   
  19.     <!-- 配置Spring监听 -->  
  20.     <listener>  
  21.         <listener-class>  
  22.                      org.springframework.web.context.ContextLoaderListener  
  23.                 </listener-class>  
  24.     </listener>  
  25.   
  26.     <!-- 配置SpringMVC -->  
  27.     <servlet>  
  28.         <servlet-name>springMVC</servlet-name>  
  29.         <servlet-class>  
  30.                          org.springframework.web.servlet.DispatcherServlet  
  31.                 </servlet-class>  
  32.         <init-param>  
  33.             <param-name>contextConfigLocation</param-name>  
  34.             <param-value>classpath*:applicationContext-*.</param-value>  
  35.         </init-param>  
  36.         <load-on-startup>1</load-on-startup>  
  37.     </servlet>  
  38.     <servlet-mapping>  
  39.         <servlet-name>springMVC</servlet-name>  
  40.         <url-pattern>/</url-pattern>  
  41.     </servlet-mapping>  
  42.   
  43.     <!-- 配置字符集 -->  
  44.     <filter>  
  45.         <filter-name>encodingFilter</filter-name>  
  46.         <filter-class>  
  47.                         org.springframework.web.filter.CharacterEncodingFilter  
  48.                 </filter-class>  
  49.         <init-param>  
  50.             <param-name>encoding</param-name>  
  51.             <param-value>UTF-8</param-value>  
  52.         </init-param>  
  53.         <init-param>  
  54.             <param-name>forceEncoding</param-name>  
  55.             <param-value>true</param-value>  
  56.         </init-param>  
  57.     </filter>  
  58.     <filter-mapping>  
  59.         <filter-name>encodingFilter</filter-name>  
  60.         <url-pattern>/*</url-pattern>  
  61.     </filter-mapping>  
  62.   
  63.     <!-- 配置Session -->  
  64.     <!-- <filter>  
  65.         <filter-name>openSession</filter-name>  
  66.         <filter-class>  
  67.                   org.springframework.orm.hibernate4.support.OpenSessionInViewFilter  
  68.                 </filter-class>  
  69.     </filter>  
  70.     <filter-mapping>  
  71.         <filter-name>openSession</filter-name>  
  72.         <url-pattern>/*</url-pattern>  
  73.     </filter-mapping> -->  
  74. </web-app>  

<?

 3、applicationContext-spring-servlet. 收藏代码

  1. <?version="1.0" encoding="UTF-8"?>  
  2. <beans "http://www.springframework.org/schema/beans"  
  3.     "http://www.w3.org/2001/"http://www.springframework.org/schema/mvc"  
  4.     "http://www.springframework.org/schema/context" "http://www.springframework.org/schema/p"  
  5.     "http://www.springframework.org/schema/aop" "http://www.springframework.org/schema/tx"  
  6.     "http://cxf.apache.org/jaxws"  
  7.     xsi:schemaLocation="  
  8.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
  9.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  10.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  11.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
  12.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
  13.         http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">  
  14.   
  15.     <!-- ? -->  
  16.     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  17.         <property name="messageConverters">  
  18.             <list>  
  19.                 <bean  
  20.                     class="org.springframework.http.converter.StringHttpMessageConverter">  
  21.                     <property name="supportedMediaTypes">  
  22.                         <list>  
  23.                             <value>  
  24.                                                                  text/plain;charset=UTF-8  
  25.                                                         </value>  
  26.                             <value>  
  27.                                                                  text/html;charset=UTF-8  
  28.                                                         </value>  
  29.                         </list>  
  30.                     </property>  
  31.                 </bean>  
  32.             </list>  
  33.         </property>  
  34.     </bean>  
  35.   
  36.     <!-- 处理静态文件 -->  
  37.     <mvc:default-servlet-handler />  
  38.   
  39.     <!-- 开启注解 -->  
  40.     <mvc:annotation-driven />  
  41.   
  42.     <!-- 使用 component-scan后,可以将此注解移除-->  
  43.     <context:annotation-config />  
  44.   
  45.     <!-- 注解扫描包 -->  
  46.     <context:component-scan base-package="com.wang" />  
  47.   
  48.     <!-- 定义视图解析器 -->  
  49.     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  50.         <property name="order" value="1" />  
  51.         <property name="prefix" value="/view/" />  
  52.         <property name="suffix" value=".jsp"></property>  
  53.     </bean>  
  54.   
  55.     <!-- 上传文件大小控制 -->  
  56.     <bean id="multipartResolver"   
  57.                 class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
  58.         <property name="maxUploadSize" value="2097152000" />  
  59.     </bean>  
  60.   
  61.     <!-- mvc拦截器,这个拦截器类要实现HandlerInterceptor这个接口 -->  
  62.     <mvc:interceptors>  
  63.         <mvc:interceptor>  
  64.             <mvc:mapping path="/**" />  
  65.             <bean class="com.wang.interceptor.TestInterceptor" />  
  66.         </mvc:interceptor>  
  67.     </mvc:interceptors>  
  68.   
  69.     <!-- aspectJ -->  
  70.     <aop:aspectj-autoproxy />  
  71.     <bean id="LogManageAop" class="com.wang.aop.LogManageAop" />  
  72.     <aop:config>  
  73.         <aop:aspect ref="LogManageAop">  
  74.             <aop:pointcut id="logPointCut"   
  75.                                expression="(execution(* com.wang.controller.*.*(..)))" />  
  76.             <aop:after pointcut-ref="logPointCut" method="saveLog" />  
  77.         </aop:aspect>  
  78.     </aop:config>  
  79.   
  80. </beans>   

<?

 

java企业级通用权限安全框架源码 SpringMVC mybatis or hibernate+ehcache shiro druid bootstrap HTML5

【java框架源码下载】