SSM搭建项目配置
所需要的jar包
jstl
jstl.jar
standard.jar
mybatis
asm-3.3.1.jar
cglib-2.2.2.jar
commons-logging-1.1.1.jar
javassist-3.17.1-GA.jar
log4j-1.2.17.jar
mybatis-3.2.1.jar
slf4j-api-1.7.2.jar
slf4j-log4j12-1.7.2.jar
servlet+jsp
jsp-api.jar
servlet-api.jar
spring
commons.logging-1.1.1.jar
spring-aop-4.1.2.RELEASE.jar
spring-beans-4.1.2.RELEASE.jar
spring-context-4.1.2.RELEASE.jar
spring-core-4.1.2.RELEASE.jar
spring-expression-4.1.2.RELEASE.jar
spring-test-4.1.2.RELEASE.jar
springmvc
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
jackson-annotations-2.5.0.jar
jackson-core-2.5.0.jar
jackson-databind-2.5.0.jar
spring-web-4.1.2.RELEASE.jar
spring-webmvc-4.1.2.RELEASE.jar
spring+mybatis
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
commons.dbcp-1.2.2.jar
commons.pool-1.5.3.jar
mybatis-spring-1.2.0.jar
spring-jdbc-4.1.2.RELEASE.jar
spring-tx-4.1.2.RELEASE.jar
mysql
mysql-connector-java-5.1.26-bin.jar
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<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"
metadata-complete="false">
<!--监听器:关联spring容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--给与监听器初始值配置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<!--applicationContext.xml定义在resources中的applicationContext.xml文件-->
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--关联核心对象spring-mvc -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!--spring-mvc.xml定义在resources中的spring-mvc.xml文件-->
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--过滤器 -->
<filter>
<filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
applicationContext.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
">
<!--导入配置文件 db.properties -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 关联数据库 -->
<!--注意事项传值时要加前缀,username他会自动寻找本机电脑名,加前缀与区别-->
<bean id="dbcp" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jbdc.driverClassName}"></property>
<property name="url" value="${jbdc.url}"></property>
<property name="username" value="${jbdc.username}"></property>
<property name="password" value="${jbdc.password}"></property>
</bean>
<!--关联核心 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="dbcp"></property>
<property name="typeAliasesPackage" value="bean类包的全限定名"></property>
<property name="mapperLocations" value="classpath:包名/*Mapper.xml"></property>
</bean >
<!--自动注册 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="mapper类包的全限定名"></property>
</bean>
<!--扫描service -->
<context:component-scan base-package="service类包的全限定名"/>
</beans>
spring-mvc.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
">
<!--静态资源放行 -->
<mvc:default-servlet-handler/>
<!--扫描包 -->
<context:component-scan base-package="controller类的包的全限定名"></context:component-scan>
<!--启动注解 -->
<mvc:annotation-driven/>
<!--视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>