一分钟搭建、运行、测试SSM项目
生活随笔
收集整理的這篇文章主要介紹了
一分钟搭建、运行、测试SSM项目
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
pom.xml
web.xml
<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"><display-name>Archetype Created Web Application</display-name><!--1. 啟動Spring容器--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!--2. Spring MVC 前端控制器 DispatcherServlet--><servlet><servlet-name>dispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><url-pattern>*.htm</url-pattern></servlet-mapping><!--3. 字符編碼, 放在所有過濾器之前--><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><init-param><param-name>forceRequestEncoding</param-name><param-value>true</param-value></init-param><init-param><param-name>forceResponseEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--4. 使用Rest風(fēng)格的URL--><filter><filter-name>HiddenHttpMethodFilter</filter-name><filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class></filter><filter-mapping><filter-name>HiddenHttpMethodFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping> </web-app>aplicationContext.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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"><context:component-scan base-package="com.mooc"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!--數(shù)據(jù)源--><context:property-placeholder location="classpath:db.properties"/><!-- 數(shù)據(jù)庫連接池 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"><property name="driverClass" value="${jdbc.driverClass}"/><property name="jdbcUrl" value="${jdbc.jdbcUrl}"/><property name="user" value="${jdbc.user}"/><property name="password" value="${jdbc.password}"/><property name="minPoolSize" value="${jdbc.miniPoolSize}"/><property name="maxPoolSize" value="${jdbc.maxPoolSize}"/><property name="initialPoolSize" value="${jdbc.initialPoolSize}"/><property name="maxIdleTime" value="${jdbc.maxIdleTime}"/><property name="acquireIncrement" value="${jdbc.acquireIncrement}"/><property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}"/><property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}"/><property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}"/><property name="automaticTestTable" value="${jdbc.automaticTestTable}"/><property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}"/><property name="checkoutTimeout" value="${jdbc.checkoutTimeout}"/></bean><!--配置和Mybatis整合--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--指定mybatis全局配置文件的位置--><property name="configLocation" value="classpath:mybatis-config.xml"/><!--數(shù)據(jù)源--><property name="dataSource" ref="dataSource"/></bean><!--配置掃描器 , 將Mybatis接口的實現(xiàn)加入到IOC容器中--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!--掃描所有的dao接口,加入到IOC容器中--><property name="basePackage" value="com.mooc.mapper"/><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/></bean> </beans>mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><settings><setting name="mapUnderscoreToCamelCase" value="true"/></settings><typeAliases><package name="com.mooc.bean"/></typeAliases><!-- 加載 映射文件 --><mappers><mapper resource="mapper/DemoMapper.xml" /></mappers> </configuration>db.properties
jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbcUrl = jdbc:mysql://localhost:3306/test jdbc.user = root jdbc.password = 123456 jdbc.miniPoolSize = 1 jdbc.maxPoolSize = 20 jdbc.initialPoolSize = 1 jdbc.maxIdleTime = 25000 jdbc.acquireIncrement = 1jdbc.acquireRetryAttempts = 30 jdbc.acquireRetryDelay = 1000 jdbc.testConnectionOnCheckin = true jdbc.automaticTestTable = c3p0TestTable jdbc.idleConnectionTestPeriod = 18000 jdbc.checkoutTimeout=3000總結(jié)
以上是生活随笔為你收集整理的一分钟搭建、运行、测试SSM项目的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Navicat Premium 12
- 下一篇: Docker Nexus3 maven