step1:
打开IDEA
step:2
选择新建的项目为Maven项目,选择JDK版本,勾选创建WEBAPP文件夹
step3:
指定项目名称和java目录结构
step4:
选择Maven路径
step5:
这是创建成功之后的项目 目录结构
—————————————————————创建MAVEN项目完结——————————————————————————————————————————
step:6
整合SSM框架,首先在pom.xml文件中,写入SSM框架所需要的JAR包
下面放我的pom.xml文件
xml version="1.0" encoding="UTF-8"?>xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 war demoTest com.lsd.demoTest demoTest 1.0-SNAPSHOT org.mortbay.jetty maven-jetty-plugin 6.1.7 implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 8888 30000 ${project.build.directory}/${pom.artifactId}-${pom.version} / UTF-8 UTF-8 4.2.5.RELEASE 3.2.8 5.1.29 1.7.18 1.2.17 jstl jstl 1.2 javax javaee-api 7.0 junit junit 4.11 test org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-oxm ${spring.version} org.springframework spring-tx ${spring.version} org.springframework spring-jdbc ${spring.version} org.springframework spring-webmvc ${spring.version} org.springframework spring-context ${spring.version} org.springframework spring-context-support ${spring.version} org.springframework spring-aop ${spring.version} org.springframework spring-test ${spring.version} org.mybatis mybatis ${mybatis.version} org.mybatis mybatis-spring 1.2.2 mysql mysql-connector-java ${mysql-driver.version} commons-dbcp commons-dbcp 1.2.2 com.alibaba fastjson 1.1.41 log4j log4j ${log4j.version} org.slf4j slf4j-api ${slf4j.version} org.slf4j slf4j-log4j12 ${slf4j.version} org.codehaus.jackson jackson-mapper-asl 1.9.13 com.fasterxml.jackson.core jackson-core 2.8.0 com.fasterxml.jackson.core jackson-databind 2.8.0 commons-fileupload commons-fileupload 1.3.1 commons-io commons-io 2.4 commons-codec commons-codec 1.9
step:7
在resources目录下创建
1.jdbc.properties(注意将jdbcUrl,username,password修改成自己的)
driverClasss=com.mysql.jdbc.Driver jdbcUrl=jdbc:mysql://192.168.1.24:3306/app?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull username=root password=123456 initialSize=0 maxActive=20 maxIdle=20 minIdle=1 maxWait=60000
2.log4j.properties
log4j.rootLogger=INFO,Console,File #控制台日志 log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.Target=System.out log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n #普通文件日志 log4j.appender.File=org.apache.log4j.RollingFileAppender log4j.appender.File.File=logs/ssm.log log4j.appender.File.MaxFileSize=10MB #输出日志,如果换成DEBUG表示输出DEBUG以上级别日志 log4j.appender.File.Threshold=ALL log4j.appender.File.layout=org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n3.spring-mvc.xml
xml version="1.0" encoding="UTF-8"?>4.spring-mybatis.xmlxmlns="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: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"> <context:component-scan base-package="com.lsd.controller"/> id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> name="supportedMediaTypes">
text/html;charset=UTF-8 class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> name="messageConverters"> bean="mappingJacksonHttpMessageConverter"/>
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> name="prefix" value="/WEB-INF/jsp/" /> name="suffix" value=".jsp"/> id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <mvc:annotation-driven />name="defaultEncoding" value="UTF-8"/> name="maxUploadSize" value="32505856"/> name="maxInMemorySize" value="4096"/>
xml version="1.0" encoding="UTF-8"?>5.web.xml(在context-param里面引入自己的配置文件)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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:component-scan base-package="com.lsd"/> id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> name="location" value="classpath:jdbc.properties"/> id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> name="driverClassName" value="${driverClasss}"/> name="url" value="${jdbcUrl}"/> name="username" value="${username}"/> name="password" value="${password}"/> name="initialSize" value="${initialSize}"> name="maxActive" value="${maxActive}"> name="maxIdle" value="${maxIdle}"> name="minIdle" value="${minIdle}"> name="maxWait" value="${maxWait}"> id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> name="dataSource" ref="dataSource"/> name="mapperLocations" value="classpath:mapping/*.xml"> class="org.mybatis.spring.mapper.MapperScannerConfigurer"> name="basePackage" value="com.lsd.dao"/> name="sqlSessionFactoryBeanName" value="sqlSessionFactory"> id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <tx:annotation-driven transaction-manager="transactionManager"/>name="dataSource" ref="dataSource"/>
xml version="1.0" encoding="UTF-8"?>至此,ssm框架搭建完成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_3_0.xsd" version="3.0"> demoTest contextConfigLocation classpath:spring-mybatis.xml log4jConfigLocation classpath:log4j.properties encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 encodingFilter /* org.springframework.web.context.ContextLoaderListener org.springframework.web.util.IntrospectorCleanupListener SpringMVC org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:spring-mvc.xml 1 true SpringMVC / /index.jsp 15
需要注意的地方:1.创建好的Maven项目没有哦java文件夹 需要自己手动创建创建好之后
如图所示 将java文件夹变成Sources文件夹。
如果自己整合的话,只需把配置文件中扫描包的路径换成自己的,就可以了
稍后会将shiro也整合进来
demo下载地址http://download.csdn.net/download/qq_40706089/10144140