`

ssm三大框架整合

阅读更多

一个简单的spring,springmvc,mybatis三大框架整合

1.spring整合springmvc

 

<?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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans    
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd    
                            http://www.springframework.org/schema/context    
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd    
                            http://www.springframework.org/schema/mvc    
                            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd    
                            http://www.springframework.org/schema/aop   
                            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

	<!-- 需要排除控制层用到的注解,比如@Controller等 -->
	<context:component-scan base-package="com.huan.shiro"
		annotation-config="true">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Service" />
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Repository" />
	</context:component-scan>
	<bean id="mappingJackson2HttpMessageConverter"
		class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
				<value>text/html;charset=UTF-8</value>
			</list>
		</property>
	</bean>
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJackson2HttpMessageConverter" />
			</list>
		</property>
	</bean>
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
	</bean>

	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="utf-8" />
		<property name="maxUploadSize" value="102400" />
		<property name="maxInMemorySize" value="40960" />
	</bean>

	<mvc:annotation-driven />

	<!-- 处理静态资源 -->
	<mvc:default-servlet-handler />
</beans>  

 2.web.xml配置文件配置( 需要注意spring的配置文件和spirngmvc的配置文件分开加载 )

 

 

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	version="3.1">
	<display-name>Archetype Created Web Application</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:spring/spring.xml
			classpath:spring/spring-mybatis.xml
		</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>dispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- 没有指定路径,默认是找WEB-INF下的 dispatcherServlet-servlet.xml文件 -->
                <init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>SpringMVC</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<async-supported>true</async-supported>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

 3.spring整合mybatis( 需要注意使用mapper扫描时,扫描的包的位置,此处我需要在mapper接口在加一个自定义注解,不然貌似有问题。 )

<?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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans    
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd    
                            http://www.springframework.org/schema/context    
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd  
                            http://www.springframework.org/schema/aop 
                            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
                            http://www.springframework.org/schema/mvc    
                            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close" init-method="init">
		<property name="driverClassName" value="${driver}" />
		<property name="url" value="${url}" />
		<property name="username" value="${username}" />
		<property name="password" value="${password}" />
		<property name="initialSize" value="${initialSize}" />
		<property name="maxActive" value="${maxActive}" />
		<property name="minIdle" value="${minIdle}" />
		<property name="maxWait" value="${maxWait}" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="true" />
		<property name="testOnReturn" value="false" />
		<property name="validationQuery" value="select 1 from dual" />
	</bean>

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations" value="classpath:sqlmaps/**/*.xml"></property>
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.huan.shiro" />
		<property name="annotationClass" value="com.huan.shiro.annotation.Mapper" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>

	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

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

 4.spring的一个配置文件

<?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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans    
                            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd    
                            http://www.springframework.org/schema/context    
                            http://www.springframework.org/schema/context/spring-context-4.0.xsd  
                            http://www.springframework.org/schema/aop 
                            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
                            http://www.springframework.org/schema/mvc    
                            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
	<!-- 自动扫描 -->
	<context:component-scan base-package="com.huan.shiro"
		annotation-config="true">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	<!-- 引入配置文件 -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
			</list>
		</property>
	</bean>
	
	<aop:aspectj-autoproxy />
</beans>  

5.pom配置文件

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.huan.shiro</groupId>
		<artifactId>shiro-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>shiro-spring</artifactId>
	<packaging>war</packaging>
	<name>shiro-spring Maven Webapp</name>
	<url>http://maven.apache.org</url>

	<properties>
		<springVersion>4.2.7.RELEASE</springVersion>
		<slf4j.version>1.7.21</slf4j.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-expression</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>4.2.7.RELEASE</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.3.0</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.2</version>
		</dependency>

		<!-- AOP begin -->
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjrt</artifactId>
			<version>1.7.4</version>
		</dependency>
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
			<version>1.7.4</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>3.1</version>
		</dependency>
		<!-- AOP end -->

		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-spring</artifactId>
			<version>${shiro.version}</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.19</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.37</version>
		</dependency>
		<dependency>
			<groupId>taglibs</groupId>
			<artifactId>standard</artifactId>
			<version>1.1.2</version>
			<type>jar</type>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
			<type>jar</type>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.2</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<!-- common-logging 实际调用slf4j -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
		</dependency>
		<!-- java.util.logging 实际调用slf4j -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jul-to-slf4j</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.7.4</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>2.7.4</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
			<version>2.7.0</version>
		</dependency>
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.9</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>shiro-spring</finalName>
	</build>
</project>

 

6.运行结果


 

可以看出,已经整合成功了。请求后台返回正常的数据。
 

 

  • 大小: 204.1 KB
分享到:
评论

相关推荐

    SSM三大框架整合详细总结(Spring+SpringMVC+MyBatis).pdf

    ### SSM三大框架整合详细总结(Spring+SpringMVC+MyBatis) #### 一、基础知识概述 **Spring** - **定义与起源**:Spring框架是一个开源的轻量级Java开发框架,它最初由Rod Johnson在2003年创建。Spring框架的主要...

    SSM三大框架整合详细教程

    SSM三大框架,即Spring、SpringMVC和MyBatis,是Java开发中常见的Web应用程序框架组合。这些框架各自有着独特的作用,共同构建了一个高效、灵活的开发环境。 1. Spring框架: Spring是一个轻量级的Java开发框架,...

    SSM三大框架整合案例

    SSM三大框架指的是Spring、Spring MVC和MyBatis,它们是Java Web开发中常用...总之,"SSM三大框架整合案例"是一个极好的学习资源,它提供了从基础到实践的全套教程,有助于Java Web开发者快速掌握SSM框架的整合与应用。

    ssm三大框架整合架包

    SSM框架是Java Web开发中常用的三大框架整合,包括Spring、Spring MVC和MyBatis。这三个框架协同工作,为开发者提供了强大的模型-视图-控制器(MVC)架构支持,提高了开发效率和代码的可维护性。下面将详细介绍这三...

    SSM三大框架整合项目(Spring+SpringMVC+MyBatis)

    SSM框架整合是Java开发中常见的技术栈,它由Spring、SpringMVC和MyBatis三个框架组成,常用于构建企业级Web应用。这三大框架的整合提供了完整的控制层、服务层和数据访问层解决方案,使得开发过程更加高效且模块化。...

    SSM三大框架整合所需要的jar包集合.zip

    SSM(Spring、SpringMVC、Mybatis)是Java Web开发中常见的三大框架,它们各自负责不同的职责,共同构建了一个完整的MVC(Model-View-Controller)架构。本压缩包包含的是SSM整合所需的jar包,旨在帮助开发者快速...

    SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis).docx

    SSM框架整合指的是Spring、SpringMVC和MyBatis的集成,这三种框架是Java Web开发中常用的组件,能够帮助开发者构建高效、灵活且易于维护的应用程序。以下是对这三个框架的基本概念和整合过程的详细说明。 1. **...

    SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis).pdf

    SSM框架整合指的是Spring、SpringMVC和MyBatis三个流行Java开发框架的集成,广泛应用于企业级Web应用开发。本文将详细介绍这三个框架的整合过程,以及各自的基本概念。 1. **Spring框架** - Spring是一个轻量级的...

    ssm三大框架的整合

    闲暇时间整理的spring,springmvc,mybatis三大框架的整合步骤,不足之处希望多多指点.

    SSM三大框架整合框架架包

    SSM框架,即Struts、Spring和MyBatis三大组件的集成,是Java Web开发中常用的后端架构。这三个框架各司其职,协同工作,为开发者提供了强大的功能和灵活性,便于构建高效、可维护的Web应用。 Struts是基于Model-...

    SSM三大框架资源整合jar包

    SSM框架是Java Web开发中常用的三大框架——Spring、Struts和MyBatis的简称。它们各自负责不同的职责,Spring作为整体的容器管理Bean,Struts处理请求与响应,MyBatis则负责数据库操作。本资源包提供的是一整套集成...

    SSM三大框架整合项目学习

    SSM框架,即Spring、SpringMVC和MyBatis,是Java Web开发中常见的三大框架。这三大框架的整合能够帮助开发者构建高效、模块化的Web应用程序。下面将详细阐述这三个框架各自的功能及其整合过程。 首先,Spring框架是...

    SSM三大框架的整合.docx

    SSM框架整合详解 在本文中,我们将详细介绍SSM框架的整合,包括Spring、Spring MVC和MyBatis的整合。SSM框架是当前最流行的Java Web开发框架,广泛应用于企业级项目中。在本文中,我们将从整合的思路、步骤开始,...

    ssm三大框架完美整合的maven项目.zip

    这个压缩包"ssm三大框架完美整合的maven项目.zip"显然包含了一个已经配置好并整合了这三大框架的Maven项目。让我们深入探讨一下这些技术以及它们的整合。 **Spring框架**:Spring是Java企业级应用的基石,它提供了...

    SSM三大框架的整合.pdf

    SSM 三大框架的整合 SSM 三大框架的整合是指 Spring、SpringMVC 和 MyBatis 三大框架的整合,目的是为了实现一个完整的 Java_web 应用程序。下面将从根本概念、整合步骤、配置实例演示三个方面对 SSM 的整合进行...

    基于Java实现的SSM框架整合实战案例

    基于Java实现的SSM框架整合实战案例 基于Java实现的SSM框架整合实战案例 基于Java实现的SSM框架整合实战案例 基于Java实现的SSM框架整合实战案例 基于Java实现的SSM框架整合实战案例 基于Java实现的SSM框架整合实战...

    ssm框架整合jar包

    SSM框架整合是JavaEE开发中的重要组成部分,它包含了Spring、Spring MVC和MyBatis这三个主流的开源框架。这三个框架的结合,为开发者提供了一种高效、灵活且易于管理的Web应用开发解决方案。 首先,Spring框架是...

    ssm框架整合redis源码

    在本项目中,"ssm框架整合redis源码"意味着开发者将SSM框架与Redis缓存系统进行了集成,主要目的是实现session共享。Session共享是Web应用中解决用户会话跨服务器问题的关键技术,尤其是在分布式环境下,确保用户...

    SSM框架整合超详细文件版,附带源码

    SSM框架整合是Java开发中常见的一种技术栈组合,由Spring、SpringMVC和Mybatis三个框架集成。这个超详细文件版旨在为初学者提供一个易于理解的搭建过程,通过附带的源码和Typora文件,使得学习者能够逐步实践,加深...

Global site tag (gtag.js) - Google Analytics