ssm-环境搭建
来源:互联网 发布:网络视频同步录制 编辑:程序博客网 时间:2024/05/22 07:46
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>myssmTest</display-name> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-*.xml</param-value> </context-param> <!-- springMVC前端控制器 --> <!-- springmvc前端控制器 、配置处理器、映射器、适配器等等--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- contextConfigLocation配置springmvc加载配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <!-- 第一种:*.action,访问以.action结尾由DispatcherServlet进行解析 第二种:/,所有访问的地址都由DispatcherServlet进行解析,对于金泰文件的解析需要配置不让DispatcherServlet进行解析 使用这种方法可以实现RESTful风格的url 第三种:/*,这样配置不对,使用这种配置,最终要转发到一个jsp页面是, 任然会有DispatcherServlet解析jsp,不能根据jsp页面找到handler,会报错 --> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 配置spring提供的字符过滤器 --> <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> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
springmvc.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "><!-- 注解扫描 --> <context:component-scan base-package="com.itcast.ssm.controller"/> <!-- 注解映射器 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> 注解适配器 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>--><!-- conversion-service="conversionService"加载自定义参数绑定 --><!-- validator:加载校验器 --><mvc:annotation-driven validator="validator"/><!-- 视图解析器 解析jsp视图,默认使用jstl标签,classpath下得有jstl的包--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 配置jsp路径的前缀 --><property name="prefix" value="/WEB-INF/jsp/"/><!-- 配置jsp路径的后缀 --><property name="suffix" value=".jsp"/></bean><!-- 自定义参数绑定 --><bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"><!-- 转换器 --><property name="converters"><list><!-- 日期类型转换 --><bean class="com.itcast.ssm.controller.converter.CustomDateConverter"/></list></property></bean><!-- 校验器 (spring提供的接口)--><bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"><!-- 校验器提供方 --><property name="providerClass" value="org.hibernate.validator.HibernateValidator"></property><!-- 指定校验使用的资源文件,在文件中配置校验错误信息,如果不注定默认使用classpath下的ValidationMessage.properties --><property name="validationMessageSource" ref="messageSource"/></bean><!-- 检验错误信息配置文件 --><bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"><!-- 资源文件名 --><property name="basenames"><list><value>classpath:CustomValidationMessages</value></list></property><!-- 资源文件编码格式 --><property name="fileEncodings" value="utf-8"/><!-- 对资源文件内容缓存时间,单位秒 --><property name="cacheSeconds" value="120"/></bean><!-- 全局异常处理器只要实现HandlerExceptionResolver接口就是全局异常处理器有且仅有一个 --><bean class="com.itcast.ssm.exception.CustomExceptionResolver"/><!-- 文件上传 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize"><value>5242880</value></property></bean><!-- 拦截器 针对HandleMapping,可单个配置--><mvc:interceptors><!-- 多个拦截器,顺序执行 --><mvc:interceptor><!-- /**表示所有url包括子url路径 --><mvc:mapping path="/**"/><bean class="com.itcast.ssm.interceptor.HandlerInterceptor1"/></mvc:interceptor><mvc:interceptor><!-- /**表示所有url包括子url路径 --><mvc:mapping path="/**"/><bean class="com.itcast.ssm.interceptor.HandlerInterceptor2"/></mvc:interceptor></mvc:interceptors></beans>
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><mappers></mappers></configuration>
applicationContext-dao.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.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!-- 加载db.properties文件中的内容 --><context:property-placeholder location="classpath:db.properties"/><!-- 配置数据源,dbcp --><bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=stdb1"></property><property name="username" value="sa"></property><property name="password" value="hyj84884824"></property><property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property></bean><!-- sqlSessionFactory --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 加载mybatis的配置文件 --><property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml"/><!-- 数据源 --><property name="dataSource" ref="dataSource"/></bean><!-- mapper扫描器 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 指定扫描的包名 --><property name="basePackage" value="com.itcast.ssm.mapper"/><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/></bean></beans>applicationContext-service.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.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"><!-- 事务管理器对mybatis操作数据库事务控制,spring使用jdbc的事务控制类 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 数据源dataSource在applicationContext-dao.xml中配置了 --><property name="dataSource" ref="dataSource"/></bean><!-- 通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- 传播行为 --><tx:method name="save*" propagation="REQUIRED"/><tx:method name="delete*" propagation="REQUIRED"/><tx:method name="insert*" propagation="REQUIRED"/><tx:method name="update*" propagation="REQUIRED"/><tx:method name="find*" propagation="SUPPORTS" read-only="true"/><tx:method name="get*" propagation="SUPPORTS" read-only="true"/><tx:method name="select*" propagation="SUPPORTS" read-only="true"/></tx:attributes></tx:advice><!-- aop --><aop:config><aop:advisor advice-ref="txAdvice" pointcut="execution(* com.itcast.ssm.service.impl.*.*(..))"/></aop:config></beans>applicationContext-transaction.xml
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="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"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.0.xsd"><!-- 商品管理的service --><bean id="itemsService" class="com.itcast.ssm.service.impl.ItemsServiceImpl"></bean><!-- --></beans>
阅读全文
0 0
- SSM+Maven环境搭建
- SSM环境搭建
- SSM--环境搭建
- ssm简单环境搭建
- SSM环境搭建
- 搭建SSM开发环境
- eclipse ssm 环境搭建
- 搭建ssm项目环境
- ssm-环境搭建
- SSM初始环境搭建
- SSM环境搭建(二)
- SSM环境搭建(一)
- SSM环境搭建(三)
- SSM环境搭建(四)
- idea+maven+ssm环境搭建
- ssm框架搭建二----环境搭建
- 【ssm个人博客项目实战01】SSM环境搭建
- SSM环境搭建——简单实现SSM整合
- bzoj 1690: [Usaco2007 Dec]奶牛的旅行(01分数规划--最优比率环)
- MYSQL Establishing SSL connection without server's identity verification is not recommended.
- Hibernate快速入门(修正可行)
- 【转载】怎样让SAP的货币、数字数据类型保留4位小数或者自定义位数小数
- 番茄工作法P001
- ssm-环境搭建
- 简单动规 最大子矩阵和
- Linux的任督二脉:进程调度和内存管理
- PhpStorm配置Xdebug断点调试
- 8月22日云栖精选夜读:新零售业务中台设计及产品体系解决方案
- CAS环境搭建-证书方式(https连接)
- 优秀的程序员10分钟内能搞定下面5个编程问题,你能做到吗?
- MFC之Tab Control的快速使用
- 杭电2022