一个简单的ssm框架的搭建
2017-12-27 20:46
483 查看
简单的ssm框架的搭建和配置文件
ssm框架里边的配置:1.src路径下直接存放数据库和log4j的properties文件
2.src路径下建个config包,分别放置ssm的xml文件
3.修改WEB-INF路径下的web.xml
4.注意放置配置文件的路径问题
1.src路径下的jdbc.propreties和log4j.properties
log4j.properties
log4j.properties里边的代码,例如:
# Global logging configuration log4j.rootLogger=DEBUG, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
jdbc.properties
jdbc.properties里边的代码,例如:
# Global logging configuration jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql:///ssm_my?useUnicode=true&characterEncoding=utf8 jdbc.username=root jdbc.password=root
2.src路径下建个config包,分别放置ssm的xml文件
applicationContext.xml
spring框架里边applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" 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.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 扫描包 --> <context:component-scan base-package="com.offcn"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- 加载配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 数据库的配置文件 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}"></property> <property name="url" value="${jdbc.url}"></property> <property name="username" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:config/SqlMapConfig.xml"></property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.offcn.mapper"></property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="find*" isolation="DEFAULT" propagation="REQUIRED" read-only="true" /> <tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" read-only="false" /> </tx:attributes> </tx:advice> <!-- aop配置 --> <aop:config> <aop:pointcut expression="execution(* com.offcn.service.*.*(..))" id="poit" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="poit" /> </aop:config> </beans>
springmvc-servlet.xml
springmvc框架里边springmvc-servlet.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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> <property name="prefix" value="/views/"></property> <property name="suffix" value=".jsp"></property> </bean> <context:component-scan base-package="com.offcn.controller"></context:component-scan> <mvc:annotation-driven> </mvc:annotation-driven> <mvc:default-servlet-handler /> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**" /> <bean class="com.offcn.interceptor.LoginInterceptor"> <property name="excuteMappingURL"> <list> <value>.js</value> <value>.css</value> <value>.png</value> <value>.gif</value> <value>.jsp</value> </list> </property> </bean> </mvc:interceptor> </mvc:interceptors> </beans>
SqlMapConfig.xml
mybatis框架里边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> <settings> <setting name="lazyLoadingEnabled" value="true" /> <setting name="aggressiveLazyLoading" value="false" /> <setting name="cacheEnabled" value="true" /> </settings> <typeAliases> <package name="com.offcn.pojo" /> </typeAliases> </configuration>
3.修改WEB-INF路径下的web.xml
WEB-INF路径下的web.xml
WEB-INF路径下的web.xml的代码,例如:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>ssm</display-name> <welcome-file-list> <welcome-file>views/login.jsp</welcome-file> </welcome-file-list> <!-- 解决字符乱码问题 --> <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> <!--springmvc的配置 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/springmvc-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- spring的配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/applicationContext.xml</param-value> </context-param> </web-app>
4.注意放置配置文件的路径问题
相关文章推荐
- 使用idea搭建一个简单的SSM框架:(1)使用idea创建maven项目
- 使用idea搭建一个简单的SSM框架:(2)配置springMVC
- 使用idea搭建一个简单的SSM框架:(3)配置spring+mybatis
- Spring boot 入门系列(一):快速搭建一个简单web系统(简单的SSM框架)
- 一个JavaWeb搭建的开源Blog系统,整合SSM框架
- Dubbo入门---搭建一个最简单的Demo框架
- SpringMVC笔记——SSM框架搭建简单实例
- 使用Node.js的express框架搭建一个简单项目并且添加了一个路由
- 搭建一个maven框架的ssm项目
- 搭建ssm框架的一个小坑
- SSM框架之一个简单的增删改查Demo
- SSM框架简单介绍以及maven环境搭建
- SSM做一个简单的网上商城-搭建项目
- [置顶] Java SSM练手小项目-手把手带你搭建一个基于SSM框架的人力资源管理后台系统
- 搭建一个简单的Spring MVC框架
- SSM第一篇 最简单的SSM框架搭建过程--SSM简单整合
- SSM框架搭建简单的前后台分离项目(后台篇)
- 利用SpringCloud搭建一个最简单的微服务框架
- Dubbo入门---搭建一个最简单的Demo框架
- ssm框架搭建(下) 简单案例