网站建设服务器搭建无水印logo在线制作免费
web/
2025/10/2 0:40:20/
文章来源:
网站建设服务器搭建,无水印logo在线制作免费,seo优化排名易下拉效率,万表网文章目录 #x1f389;SSM整合流程一、两个容器整合✨ 1、先准备好数据库config.properties连接、mybatis-config.xml#x1f38a; 2、容器一#xff1a;优先配置spring.xml文件#x1f38a; 3、容器二#xff1a;配置springMVC.xml文件#x1f38a; 4、Tomcat整合spring… 文章目录 SSM整合流程一、两个容器整合✨ 1、先准备好数据库config.properties连接、mybatis-config.xml 2、容器一优先配置spring.xml文件 3、容器二配置springMVC.xml文件 4、Tomcat整合spring容器、springMVC容器webapp文件下的web.xml文件 二、一个容器整合1、 现在去掉了spring.xml文件将spring.xml文件的内容放到springMVC 2、Tomcat整合springMVC容器webapp文件下的web.xml文件 SSM整合流程 分为两种两个容器整合 一个容器整合 本项目的路径参考 注意优先maven项目的pom.xml文件里导入jar包依赖 propertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncodingaaa4.3.8.RELEASE/aaa/propertiesdependenciesdependencygroupIdcom.auth0/groupIdartifactIdjava-jwt/artifactIdexclusionsexclusiongroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactId/exclusion/exclusionsversion3.19.2/version/dependencydependencygroupIdorg.dom4j/groupIdartifactIddom4j/artifactIdversion2.0.0/versiontypepom/type!--依赖的类型声明引入的依赖的类型值一般有jar、war、pom--/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.11/versionscopetest/scope/dependency!-- spring的webmvc的依赖 --dependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion${aaa}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-web/artifactIdversion${aaa}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-tx/artifactIdversion${aaa}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-core/artifactIdversion4.3.8.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-beans/artifactIdversion4.3.8.RELEASE/version/dependency!-- Mysql的依赖 --dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.28/version/dependency!-- mybatis的依赖 --dependencygroupIdorg.mybatis/groupIdartifactIdmybatis/artifactIdversion3.5.6/version/dependency!--数据库连接池的依赖 --dependencygroupIdcommons-dbcp/groupIdartifactIdcommons-dbcp/artifactIdversion1.4/version/dependency!-- spring-mybatis的依赖 --dependencygroupIdorg.mybatis/groupIdartifactIdmybatis-spring/artifactIdversion1.3.2/version/dependency!-- springjdbc的依赖 --dependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion4.3.8.RELEASE/version/dependency!-- aspectj的依赖 --dependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactIdversion1.9.4/version/dependency!-- 添加日志log4j的依赖 --dependencygroupIdlog4j/groupIdartifactIdlog4j/artifactIdversion1.2.17/version/dependency!-- jackson的依赖 --!-- dependency--!-- groupIdcom.fasterxml.jackson.core/groupId--!-- artifactIdjackson-databind/artifactId--!-- version2.9.7/version--!-- /dependency--!-- 依赖 --dependencygroupIdaopalliance/groupIdartifactIdaopalliance/artifactIdversion1.0/version/dependencydependencygroupIdorg.apache.tomcat/groupIdartifactIdtomcat-servlet-api/artifactIdversion8.0.28/versionscopeprovided/scope!-- 生命周期test --/dependencydependencygroupIdjavax.servlet/groupIdartifactIdjavax.servlet-api/artifactIdversion3.0.1/versionscopeprovided/scope/dependencydependencygroupIdjavax.servlet.jsp/groupIdartifactIdjsp-api/artifactIdversion2.1/versionscopeprovided/scope/dependency!-- json依赖 --dependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactIdversion1.2.71/version/dependency!--导入lombok依赖 --dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.8/version/dependencydependencygroupIdjavax.servlet/groupIdartifactIdjstl/artifactIdversion1.2/version/dependencydependencygroupIdtaglibs/groupIdartifactIdstandard/artifactIdversion1.1.2/version/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.3.2/version/dependencydependencygroupIdorg.apache.httpcomponents/groupIdartifactIdhttpclient/artifactIdversion4.5.5/version/dependency!-- https://mvnrepository.com/artifact/com.mchange/c3p0 --dependencygroupIdcom.mchange/groupIdartifactIdc3p0/artifactIdversion0.9.5.2/version/dependency!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --dependencygroupIdcom.google.code.gson/groupIdartifactIdgson/artifactIdversion2.8.5/version/dependency!-- https://mvnrepository.com/artifact/org.jdom/jdom2 --dependencygroupIdorg.jdom/groupIdartifactIdjdom2/artifactIdversion2.0.6/version/dependency!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --dependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactIdversion1.2.71/version/dependencydependencygroupIdorg.testng/groupIdartifactIdtestng/artifactIdversionRELEASE/versionscopecompile/scope/dependencydependencygroupIdcommons-fileupload/groupIdartifactIdcommons-fileupload/artifactIdversion1.4/version/dependency!-- redis客户端jar --dependencygroupIdredis.clients/groupIdartifactIdjedis/artifactIdversion2.7.3/version/dependency!-- spring-redis实现 --dependencygroupIdorg.springframework.data/groupIdartifactIdspring-data-redis/artifactIdversion1.7.2.RELEASE/version/dependencydependencygroupIdio.jsonwebtoken/groupIdartifactIdjjwt-api/artifactIdversion0.11.2/version/dependencydependencygroupIdio.jsonwebtoken/groupIdartifactIdjjwt-impl/artifactIdversion0.11.2/version/dependencydependencygroupIdio.jsonwebtoken/groupIdartifactIdjjwt-jackson/artifactIdversion0.11.2/version/dependency/dependencies一、两个容器整合✨ 1、先准备好数据库config.properties连接、mybatis-config.xml
1数据库config.properties连接
drivercom.mysql.cj.jdbc.Driver
urljdbc:mysql://localhost:3306/emp?serverTimeZoneAsia/ShangHaiuseUnicodetruecharacterEncodingutf8useSSLfalse
usernameroot
passwordnigx01282mybatis-config.xml
?xml version1.0 encodingUTF-8 ?
!DOCTYPE configurationPUBLIC -//mybatis.org//DTD Config 3.0//ENhttp://mybatis.org/dtd/mybatis-3-config.dtdconfiguration!-- properties resourceconfig.properties --!-- /properties --settings!--将表中字段的下划线自动转换为驼峰--setting namemapUnderscoreToCamelCase valuetrue/setting namelogImpl valueSTDOUT_LOGGING/!-- 如果需要更改一级缓存的范围可以在Mybatis的配置文件中在下通过localCacheScope指定。 --!-- setting namelocalCacheScope valueSTATEMENT/ --/settings!-- 类型别名配置各个标签时需要遵守前后顺序--typeAliasespackage namecom.pojo//typeAliases!-- typeAliases--!-- typeAlias aliasuser typecom.pojo.User/typeAlias--!-- typeAlias typecom.pojo.Employee/typeAlias--!-- typeAlias typecom.pojo.Log/typeAlias--!-- typeAlias typecom.pojo.Dept/typeAlias--!-- /typeAliases--!-- environments配置数据库的连接环境信息可以配置多个environment通过default属性切换不同的environment --!-- environments defaultdevelopment --!-- environment iddevelopment --!-- transactionManager typeJDBC/ --!-- lt;!ndash;数据库连接池ndash;gt; --!-- dataSource typePOOLED --!-- lt;!ndash;数据库的连接信息ndash;gt; --!-- property namedriver value${driver}/ --!-- property nameurl value${url}/ --!-- property nameusername value${username}/ --!-- property namepassword value${password}/ --!-- /dataSource --!-- /environment --!-- /environments --mappers!--加载SQL映射文件--!--mapper resourcenigaoxian\mapper\UserMapper.xml/--!-- Mapper 代理方式在spring容器映射过就不需要配置了--!-- package namecom.dao/ --/mappers
/configuration2、容器一优先配置spring.xml文件
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/context xmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd!-- 2*31 --!--扫描组件除控制层--context:component-scan base-packagecom.service,com.service.serviceImpl,com.interceptor,com.exception!-- 按照注解进行排除标注了指定注解的组件不要扫描 --!-- context:exclude-filter typeannotation expressionorg.springframework.stereotype.Controller/--!-- 指定排除某个具体的类按照类排除 --!-- context:exclude-filter typeassignable expressioncom.controller.EmpController/ --/context:component-scan!-- 配置数据源 --!--引入config.properties--bean classorg.springframework.beans.factory.config.PropertyPlaceholderConfigurerproperty namelocationslistvalueclasspath:config.properties/value/list/property/bean!-- 配置数据参数与连接属性 --bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSource destroy-methodcloseproperty namedriverClass value${driver}/propertyproperty namemaxPoolSize value100/propertyproperty nameminPoolSize value30/propertyproperty namejdbcUrl value${url}/propertyproperty nameuser value${username}/propertyproperty namepassword value${password}/property/bean!-- 配置spring事务管理器 --bean idtransactionManagerclassorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource//bean!--开启事务的注解驱动将使用注解 Transactional 标识的方法或类中所有的方法进行事务关联--tx:annotation-driven transaction-managertransactionManager/!-- 配置SqlSessionFactoryBean可以直接在Spring的IOC中获取SqlSessionFactory--bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBean!-- 设置MyBatis的核心配置文件的路径 --property nameconfigLocation valueclasspath:mybatis-config.xml/!-- 设置数据源 --property namedataSource refdataSource/!-- 设置类型别名默认为类名 --!-- property nametypeAliasesPackage valuecom.pojo/ --!-- 设置映射文件所在的包只有在映射文件的包和mapper接口的包不一致时需要设置 --property namemapperLocations valueclasspath:com/dao/*.xml/!--引入分页插件--!-- property nameplugins --!-- array --!-- bean classcom.github.pagehelper.PageInterceptor/ --!-- /array --!-- /property --/bean!--配置mapper接口的扫描配置由mybatis-spring提供可以将指定包下所有的mapper接口创建动态代理并将这些动态代理作为IOC容器的bean管理可以直接在Spring的IOC中获取Mapper接口了。--bean classorg.mybatis.spring.mapper.MapperScannerConfigurerproperty namesqlSessionFactoryBeanName valuesqlSessionFactory/property namebasePackage valuecom.dao//bean
/beans3、容器二配置springMVC.xml文件
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxmlns:mvchttp://www.springframework.org/schema/mvcxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd!-- 启动mvc注解驱动 --mvc:annotation-driven/!-- 配置扫描的包 --context:component-scan base-packagecom.controller/!-- 配置视图解析器 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value//propertyproperty namesuffix value.jsp/property/beanmvc:corsmvc:mapping path/** allowed-origins* allowed-headers* allowed-methods* allow-credentialsfalsemax-age3600//mvc:corsmvc:interceptorsmvc:interceptormvc:mapping path/**/bean idcorsInterceptor classcom.interceptor.CORSInterceptor//mvc:interceptormvc:interceptormvc:mapping path/**/mvc:exclude-mapping path/login/mvc:exclude-mapping path/register/bean idloginInterceptor classcom.interceptor.LoginInterceptor//mvc:interceptor/mvc:interceptors
/beans4、Tomcat整合spring容器、springMVC容器webapp文件下的web.xml文件
!DOCTYPE web-app PUBLIC-//Sun Microsystems, Inc.//DTD Web Application 2.3//ENhttp://java.sun.com/dtd/web-app_2_3.dtd web-app xmlnshttp://xmlns.jcp.org/xml/ns/javaeexmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsdversion4.0!-- tomcat整合spring --!--配置Spring的编码过滤器--!--配置Spring的监听器在服务器启动的时候加载Spring的配置文件 --listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener!--设置spring配置文件自定义的位置和名称--context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:spring.xml/param-value/context-param!-- filter --!-- filter-nameCharacterEncodingFilter/filter-name --!-- filter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-class --!-- lt;!ndash;只设置这个只会处理请求的编码两个都设置请求响应都会处理ndash;gt; --!-- init-param --!-- param-nameencoding/param-name --!-- param-valueUTF-8/param-value --!-- /init-param --!-- init-param --!-- param-nameforceEncoding/param-name --!-- param-valuetrue/param-value --!-- /init-param --!-- /filter --!-- filter-mapping --!-- filter-nameCharacterEncodingFilter/filter-name --!-- url-pattern/*/url-pattern --!-- /filter-mapping --!-- lt;!ndash; 配置处理请求方式PUT和DELETE的过滤器ndash;gt; --!-- filter --!-- filter-nameHiddenHttpMethodFilter/filter-name --!-- filter-classorg.springframework.web.filter.HiddenHttpMethodFilter/filter-class --!-- /filter --!-- filter-mapping --!-- filter-nameHiddenHttpMethodFilter/filter-name --!-- url-pattern/*/url-pattern --!-- /filter-mapping --!-- tomcat整合spring --!-- 配置SpringMVC的前端控制器 --servletservlet-nameDispatcherServlet/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class!-- 设置SpringMVC的配置文件的位置和名称 --init-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:springMVC.xml/param-value/init-param!-- 将DispatcherServlet的初始化时间提前到服务器启动时--load-on-startup1/load-on-startup/servlet!-- 为什么使用/并且这里为什么会默认放行jsp设置/是为了兜底的因为只有一个servlet就是默认为DispatcherServlet的servlet需要使用这个servlet拦截请求。因为jsp底层本身就是servlet设置多个servlet此时只映射的是DispatcherServlet--servlet-mappingservlet-nameDispatcherServlet/servlet-nameurl-pattern//url-pattern/servlet-mapping/web-app二、一个容器整合
1、 现在去掉了spring.xml文件将spring.xml文件的内容放到springMVC
springMVC.xml文件如下
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxmlns:mvchttp://www.springframework.org/schema/mvcxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd!-- 2*31 --!--扫描组件除控制层--context:component-scan base-packagecom.service,com.service.serviceImpl,com.interceptor,com.exception!-- 按照注解进行排除标注了指定注解的组件不要扫描 --!-- context:exclude-filter typeannotation expressionorg.springframework.stereotype.Controller/--!-- 指定排除某个具体的类按照类排除 --!-- context:exclude-filter typeassignable expressioncom.controller.EmpController/ --/context:component-scan!-- 配置数据源 --!--引入config.properties--bean classorg.springframework.beans.factory.config.PropertyPlaceholderConfigurerproperty namelocationslistvalueclasspath:config.properties/value/list/property/bean!-- 配置数据参数与连接属性 --bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSource destroy-methodcloseproperty namedriverClass value${driver}/propertyproperty namemaxPoolSize value100/propertyproperty nameminPoolSize value30/propertyproperty namejdbcUrl value${url}/propertyproperty nameuser value${username}/propertyproperty namepassword value${password}/property/bean!-- 配置spring事务管理器 --bean idtransactionManagerclassorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource//bean!--开启事务的注解驱动将使用注解 Transactional 标识的方法或类中所有的方法进行事务关联--tx:annotation-driven transaction-managertransactionManager/!-- 配置SqlSessionFactoryBean可以直接在Spring的IOC中获取SqlSessionFactory--bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBean!-- 设置MyBatis的核心配置文件的路径 --property nameconfigLocation valueclasspath:mybatis-config.xml/!-- 设置数据源 --property namedataSource refdataSource/!-- 设置类型别名默认为类名 --!-- property nametypeAliasesPackage valuecom.pojo/ --!-- 设置映射文件所在的包只有在映射文件的包和mapper接口的包不一致时需要设置 --property namemapperLocations valueclasspath:com/dao/*.xml/!--引入分页插件--!-- property nameplugins --!-- array --!-- bean classcom.github.pagehelper.PageInterceptor/ --!-- /array --!-- /property --/bean!--配置mapper接口的扫描配置由mybatis-spring提供可以将指定包下所有的mapper接口创建动态代理并将这些动态代理作为IOC容器的bean管理可以直接在Spring的IOC中获取Mapper接口了。--bean classorg.mybatis.spring.mapper.MapperScannerConfigurerproperty namesqlSessionFactoryBeanName valuesqlSessionFactory/property namebasePackage valuecom.dao//bean!-- 启动mvc注解驱动 --mvc:annotation-driven/!-- 配置扫描的包 --context:component-scan base-packagecom.controller/!-- 配置视图解析器 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value//propertyproperty namesuffix value.jsp/property/beanmvc:corsmvc:mapping path/** allowed-origins* allowed-headers* allowed-methods* allow-credentialsfalsemax-age3600//mvc:corsmvc:interceptorsmvc:interceptormvc:mapping path/**/bean idcorsInterceptor classcom.interceptor.CORSInterceptor//mvc:interceptormvc:interceptormvc:mapping path/**/mvc:exclude-mapping path/login/mvc:exclude-mapping path/register/bean idloginInterceptor classcom.interceptor.LoginInterceptor//mvc:interceptor/mvc:interceptors
/beans2、Tomcat整合springMVC容器webapp文件下的web.xml文件
!DOCTYPE web-app PUBLIC-//Sun Microsystems, Inc.//DTD Web Application 2.3//ENhttp://java.sun.com/dtd/web-app_2_3.dtd web-app xmlnshttp://xmlns.jcp.org/xml/ns/javaeexmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsdversion4.0!-- tomcat整合springMVC --!-- 配置SpringMVC的前端控制器 --servletservlet-nameDispatcherServlet/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class!-- 设置SpringMVC的配置文件的位置和名称 --init-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:springMVC.xml/param-value/init-param!-- 将DispatcherServlet的初始化时间提前到服务器启动时--load-on-startup1/load-on-startup/servlet!-- 为什么使用/并且这里为什么会默认放行jsp设置/是为了兜底的因为只有一个servlet就是默认为DispatcherServlet的servlet需要使用这个servlet拦截请求。因为jsp底层本身就是servlet设置多个servlet此时只映射的是DispatcherServlet--servlet-mappingservlet-nameDispatcherServlet/servlet-nameurl-pattern//url-pattern/servlet-mapping/web-app
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/85333.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!