--------------------- 作者:凉城古梦喵扑街 来源:CSDN 原文:https://blog.csdn.net/ssh159/article/details/80529428?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!
从eclipse换到idea,SSM的项目跟maven真的不好配置,下面讲解踩坑步骤(感谢A+大佬帮助以及论坛大佬们的demo)
项目结构:
一、设置Maven:
Maven的官网 点击打开链接
下载解压后,到 maven-XXX /conf/ settings.xml 里配置下,;
1,找到localRepository,设置你的jar包储存目录,可自定义
比如我:
<localRepository>F:\Java\apache-maven-3.3.9\repo</localRepository>
2,配置云端链接,下载jar包的地址,为了防止有墙或者单个云端挂了,
我们设置三个地址保险一点
-
<mirror>
-
<id>alimaven</id>
-
<name>aliyun maven</name>
-
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
-
<mirrorOf>central</mirrorOf>
-
</mirror>
-
<mirror>
-
<id>ui</id>
-
<mirrorOf>central</mirrorOf>
-
<name>Human Readable Name for this Mirror.</name>
-
<url>http://uk.maven.org/maven2/</url>
-
</mirror>
-
<mirror>
-
<id>sprintio</id>
-
<mirrorOf>central</mirrorOf>
-
<name>Human Readable Name for this Mirror.</name>
-
<url>https://repo.spring.io/libs-snapshot/</url>
-
</mirror>
二、idea创建项目:
1、next->new window open 在新的窗口打开,
这里暂时不用脚手架 ,我的包名是:com.spring
填写你的包名跟项目名后,开始搭建框架
ssmwork,ssmdemo都行,
新建后,这里有java,resources文件,pom.xml,这些都是大致文件
2、main.java
-
package com.spring.controller;
-
import com.spring.pojo.Admin;
-
import com.spring.service.AdminService;
-
import org.springframework.stereotype.Controller;
-
import org.springframework.web.bind.annotation.PathVariable;
-
import org.springframework.web.bind.annotation.RequestMapping;
-
import org.springframework.web.bind.annotation.RequestMethod;
-
import org.springframework.web.bind.annotation.ResponseBody;
-
import javax.annotation.Resource;
-
@Controller
-
public class main {
-
@Resource
-
AdminService adminService;
-
@RequestMapping("/")
-
@ResponseBody
-
public String index(){
-
return "hello world";
-
}
-
@RequestMapping(value = "/admin",method = RequestMethod.POST)
-
@ResponseBody
-
public int insertUser(Admin admin){
-
return adminService.insertAdmin(admin);
-
}
-
@RequestMapping(value = "/admin/{id}",method = RequestMethod.GET)
-
@ResponseBody
-
public Admin getUser(@PathVariable Integer id){
-
return adminService.getAdmin(id);
-
}
-
}
3、AdminMapper.java (接口)
-
package com.spring.dao;
-
import com.spring.pojo.Admin;
-
public interface AdminMapper {
-
int deleteByPrimaryKey(Integer id);
-
int insert(Admin record);
-
int insertSelective(Admin record);
-
Admin selectByPrimaryKey(Integer id);
-
int updateByPrimaryKeySelective(Admin record);
-
int updateByPrimaryKey(Admin record);
-
}
4、Admin.java(实体类)
-
package com.spring.pojo;
-
public class Admin {
-
private Integer id;
-
private String name;
-
private String password;
-
public Integer getId() {
-
return id;
-
}
-
public void setId(Integer id) {
-
this.id = id;
-
}
-
public String getName() {
-
return name;
-
}
-
public void setName(String name) {
-
this.name = name == null ? null : name.trim();
-
}
-
public String getPassword() {
-
return password;
-
}
-
public void setPassword(String password) {
-
this.password = password == null ? null : password.trim();
-
}
-
}
5、AdminService.java(业务逻辑处理层)
-
package com.spring.service;
-
import com.spring.pojo.Admin;
-
import com.spring.dao.AdminMapper;
-
import com.spring.pojo.Admin;
-
import org.springframework.stereotype.Service;
-
import javax.annotation.Resource;
-
@Service("AdminService")
-
public class AdminService {
-
@Resource
-
protected AdminMapper adminMapper;
-
public Admin getAdmin(int id){
-
Admin a=this.adminMapper.selectByPrimaryKey(id);
-
if(a!=null){
-
return a;
-
}
-
return null;
-
}
-
public int insertAdmin(Admin admin){
-
return this.adminMapper.insert(admin);
-
}
-
}
6、AdminMapper.xml(映射)
-
<?xml version="1.0" encoding="UTF-8" ?>
-
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
-
<mapper namespace="com.spring.dao.AdminMapper" >
-
<resultMap id="BaseResultMap" type="com.spring.pojo.Admin" >
-
<id column="id" property="id" jdbcType="INTEGER" />
-
<result column="name" property="name" jdbcType="VARCHAR" />
-
<result column="password" property="password" jdbcType="VARCHAR" />
-
</resultMap>
-
<sql id="Base_Column_List" >
-
id, name, password
-
</sql>
-
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
-
select
-
<include refid="Base_Column_List" />
-
from admin
-
where id = #{id,jdbcType=INTEGER}
-
</select>
-
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
-
delete from admin
-
where id = #{id,jdbcType=INTEGER}
-
</delete>
-
<insert id="insert" parameterType="com.spring.pojo.Admin" >
-
insert into admin (id, name, password
-
)
-
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}
-
)
-
</insert>
-
<insert id="insertSelective" parameterType="com.spring.pojo.Admin" >
-
insert into admin
-
<trim prefix="(" suffix=")" suffixOverrides="," >
-
<if test="id != null" >
-
id,
-
</if>
-
<if test="name != null" >
-
name,
-
</if>
-
<if test="password != null" >
-
password,
-
</if>
-
</trim>
-
<trim prefix="values (" suffix=")" suffixOverrides="," >
-
<if test="id != null" >
-
#{id,jdbcType=INTEGER},
-
</if>
-
<if test="name != null" >
-
#{name,jdbcType=VARCHAR},
-
</if>
-
<if test="password != null" >
-
#{password,jdbcType=VARCHAR},
-
</if>
-
</trim>
-
</insert>
-
<update id="updateByPrimaryKeySelective" parameterType="com.spring.pojo.Admin" >
-
update admin
-
<set >
-
<if test="name != null" >
-
name = #{name,jdbcType=VARCHAR},
-
</if>
-
<if test="password != null" >
-
password = #{password,jdbcType=VARCHAR},
-
</if>
-
</set>
-
where id = #{id,jdbcType=INTEGER}
-
</update>
-
<update id="updateByPrimaryKey" parameterType="com.spring.pojo.Admin" >
-
update admin
-
set name = #{name,jdbcType=VARCHAR},
-
password = #{password,jdbcType=VARCHAR}
-
where id = #{id,jdbcType=INTEGER}
-
</update>
-
</mapper>
三、resources设置
1、jdbc.properties (数据库设置连接层)
-
driver=com.mysql.jdbc.Driver
-
url=jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8
-
username=root
-
password=123456
-
#定义初始连接数
-
initialSize=0
-
#定义最大连接数
-
maxActive=20
-
#定义最大空闲
-
maxIdle=20
-
#定义最小空闲
-
minIdle=1
-
#定义最长等待时间
-
maxWait=60000
2、log4j.properties(日志文件记录)
-
#定义LOG输出级别
-
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=[%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] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
3、log4j.xml
-
<?xml version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE log4j:configuration SYSTEM "http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd">
-
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://jakarta.apache.org/log4j/ ">
-
<!-- ===================================================================== -->
-
<!-- 定义全局输出适配器 -->
-
<!-- ===================================================================== -->
-
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
-
<layout class="org.apache.log4j.PatternLayout">
-
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}]-[%c]-[%t] %x - %m%n"/>
-
</layout>
-
</appender>
-
<!-- Mybatis and SQL -->
-
<logger name="org.apache.ibatis" additivity="true">
-
<level value="DEBUG"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<logger name="org.mybatis.spring" additivity="true">
-
<level value="ERROR"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<logger name="java.sql" additivity="true">
-
<level value="DEBUG"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<logger name="java.sql.Connection" additivity="true">
-
<level value="DEBUG"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<logger name="java.sql.Statement" additivity="true">
-
<level value="DEBUG"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<logger name="java.sql.PreparedStatement" additivity="true">
-
<level value="DEBUG"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<!-- Spring -->
-
<logger name="org.springframework" additivity="true">
-
<level value="ERROR"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<!-- ActiveMQ -->
-
<logger name="org.apache.activemq" additivity="true">
-
<level value="ERROR"/>
-
<appender-ref ref="consoleAppender"/>
-
</logger>
-
<!-- ===================================================================== -->
-
<!-- 根日志记录器 -->
-
<!-- ===================================================================== -->
-
<root>
-
<level value="DEBUG"/>
-
<appender-ref ref="consoleAppender"/>
-
</root>
-
</log4j:configuration>
4、mybatis-config.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="logImpl" value="LOG4J" />
-
<setting name="cacheEnabled" value="true"/>
-
</settings>
-
</configuration>
5、spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
-
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/mvc
-
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
-
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
-
<context:component-scan base-package="com.spring.controller" />
-
<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
-
<bean id="mappingJacksonHttpMessageConverter"
-
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
-
<property name="supportedMediaTypes">
-
<list>
-
<value>text/html;charset=UTF-8</value>
-
</list>
-
</property>
-
</bean>
-
<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
-
<bean
-
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
-
<property name="messageConverters">
-
<list>
-
<ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON转换器 -->
-
</list>
-
</property>
-
</bean>
-
<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
-
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
-
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
-
<property name="prefix" value="/WEB-INF/page/" />
-
<property name="suffix" value=".jsp" />
-
</bean>
-
<!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->
-
<bean id="multipartResolver"
-
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
-
<!-- 默认编码 -->
-
<property name="defaultEncoding" value="utf-8" />
-
<!-- 文件大小最大值 -->
-
<property name="maxUploadSize" value="10485760000" />
-
<!-- 内存中的最大值 -->
-
<property name="maxInMemorySize" value="40960" />
-
</bean>
-
</beans>
6、spring-mybatis.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:mvc="http://www.springframework.org/schema/mvc"
-
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/mvc
-
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
-
<!-- 自动扫描 -->
-
<context:component-scan base-package="com.spring" />
-
<!-- 引入配置文件 -->
-
<bean id="propertyConfigurer"
-
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-
<property name="location" value="classpath:jdbc.properties" />
-
</bean>
-
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
-
destroy-method="close">
-
<property name="driverClassName" value="${driver}" />
-
<property name="url" value="${url}" />
-
<property name="username" value="${username}" />
-
<property name="password" value="${password}" />
-
<!-- 初始化连接大小 -->
-
<property name="initialSize" value="${initialSize}"></property>
-
<!-- 连接池最大数量 -->
-
<property name="maxActive" value="${maxActive}"></property>
-
<!-- 连接池最大空闲 -->
-
<property name="maxIdle" value="${maxIdle}"></property>
-
<!-- 连接池最小空闲 -->
-
<property name="minIdle" value="${minIdle}"></property>
-
<!-- 获取连接最大等待时间 -->
-
<property name="maxWait" value="${maxWait}"></property>
-
</bean>
-
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
-
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-
<property name="dataSource" ref="dataSource" />
-
<property name="configLocation" value="classpath:/mybatis-config.xml"></property>
-
<!-- 自动扫描mapping.xml文件 -->
-
<property name="mapperLocations" value="classpath:com/spring/mapping/*.xml"/>
-
</bean>
-
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
-
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
-
<property name="basePackage" value="com.spring.dao" />
-
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
-
</bean>
-
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
-
<bean id="transactionManager"
-
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-
<property name="dataSource" ref="dataSource" />
-
</bean>
-
</beans>
四、其他资源:
1、webapp下的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://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>SSMDemoTwo</display-name>
-
<welcome-file-list>
-
<welcome-file>index.html</welcome-file>
-
<welcome-file>index.jsp</welcome-file>
-
</welcome-file-list>
-
<!-- Spring和mybatis的配置文件 -->
-
<context-param>
-
<param-name>contextConfigLocation</param-name>
-
<param-value>classpath:spring-mybatis.xml</param-value>
-
</context-param>
-
<!--Log4j配置-->
-
<context-param>
-
<param-name>log4jRefreshInterval</param-name>
-
<param-value>60000</param-value>
-
</context-param>
-
<listener>
-
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
-
</listener>
-
<!-- 编码过滤器 -->
-
<filter>
-
<filter-name>encodingFilter</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>encodingFilter</filter-name>
-
<url-pattern>/*</url-pattern>
-
</filter-mapping>
-
<!--Spring监听器 ApplicationContext 载入 -->
-
<listener>
-
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-
</listener>
-
<!-- 防止Spring内存溢出监听器 -->
-
<listener>
-
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
-
</listener>
-
<!-- Spring MVC 核心配置开始 -->
-
<servlet>
-
<servlet-name>mvc-dispatcher</servlet-name>
-
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
-
<!-- 可以通过contextConfigLocation来自定义SpringMVC配置文件的位置,如不指定,则默认在WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,
-
此时文件名必须为[<servlet-name>]-servlet.xml,否则会出错-->
-
<!--以下init-param是自定义SpringMVC的配置文件的位置 -->
-
<init-param>
-
<param-name>contextConfigLocation</param-name>
-
<param-value>classpath:spring-mvc.xml</param-value>
-
</init-param>
-
<load-on-startup>1</load-on-startup>
-
<async-supported>true</async-supported>
-
</servlet>
-
<!-- 拦截设置 -->
-
<servlet-mapping>
-
<servlet-name>mvc-dispatcher</servlet-name>
-
<!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
-
<url-pattern>/</url-pattern>
-
</servlet-mapping>
-
<!-- Spring MVC 核心配置结束 -->
-
<!-- 配置SESSION超时,单位是分钟 -->
-
<session-config>
-
<session-timeout>15</session-timeout>
-
</session-config>
-
</web-app>
2、pom.xml 注意你的包名
温馨提示:mysql 5.1.46这个jar包可以兼容5.6,5.7的版本
build 里面的 port , 可以自定义端口名,这里是8081,项目名是 ssmdemotwo
-
<?xml version="1.0" encoding="UTF-8"?>
-
<project 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/xsd/maven-4.0.0.xsd">
-
<modelVersion>4.0.0</modelVersion>
-
<groupId>com.ssm.DemoTwo</groupId>
-
<artifactId>DemoTwo</artifactId>
-
<version>1.0-SNAPSHOT</version>
-
<name>hugo Maven Webapp</name>
-
<url>http://maven.apache.org</url>
-
<properties>
-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-
<!-- spring版本号 -->
-
<spring.version>4.1.4.RELEASE</spring.version>
-
<!-- mybatis版本号 -->
-
<mybatis.version>3.2.8</mybatis.version>
-
<!-- log4j日志文件管理包版本 -->
-
<slf4j.version>1.7.7</slf4j.version>
-
<log4j.version>1.2.17</log4j.version>
-
<!-- jackson包版本 -->
-
<jackson.version>2.5.0</jackson.version>
-
</properties>
-
<dependencies>
-
<dependency>
-
<groupId>junit</groupId>
-
<artifactId>junit</artifactId>
-
<version>3.8.1</version>
-
<scope>test</scope>
-
</dependency>
-
<!-- mybatis核心包 -->
-
<dependency>
-
<groupId>org.mybatis</groupId>
-
<artifactId>mybatis</artifactId>
-
<version>${mybatis.version}</version>
-
</dependency>
-
<!-- mybatis/spring包 -->
-
<dependency>
-
<groupId>org.mybatis</groupId>
-
<artifactId>mybatis-spring</artifactId>
-
<version>1.2.2</version>
-
</dependency>
-
<!--spring单元测试依赖 -->
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-test</artifactId>
-
<version>4.1.7.RELEASE</version>
-
<scope>test</scope>
-
</dependency>
-
<!-- springMVC核心包 -->
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-webmvc</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<!-- spring核心包 -->
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-core</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-beans</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-context</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-context-support</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-tx</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-web</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-jdbc</artifactId>
-
<version>${spring.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>javax.servlet</groupId>
-
<artifactId>javax.servlet-api</artifactId>
-
<version>3.0.1</version>
-
<scope>provided</scope>
-
</dependency>
-
<dependency>
-
<groupId>javax.servlet.jsp</groupId>
-
<artifactId>jsp-api</artifactId>
-
<version>2.2</version>
-
<scope>provided</scope>
-
</dependency>
-
<!-- 导入Mysql数据库链接jar包 -->
-
<dependency>
-
<groupId>mysql</groupId>
-
<artifactId>mysql-connector-java</artifactId>
-
<version>5.1.46</version>
-
</dependency>
-
<!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->
-
<dependency>
-
<groupId>commons-dbcp</groupId>
-
<artifactId>commons-dbcp</artifactId>
-
<version>1.2.2</version>
-
</dependency>
-
<!-- JSTL标签类 -->
-
<dependency>
-
<groupId>jstl</groupId>
-
<artifactId>jstl</artifactId>
-
<version>1.2</version>
-
</dependency>
-
<!-- 日志文件管理包 -->
-
<!-- log start -->
-
<dependency>
-
<groupId>log4j</groupId>
-
<artifactId>log4j</artifactId>
-
<version>${log4j.version}</version>
-
</dependency>
-
<!-- 格式化对象,方便输出日志 -->
-
<dependency>
-
<groupId>com.alibaba</groupId>
-
<artifactId>fastjson</artifactId>
-
<version>1.1.41</version>
-
</dependency>
-
<dependency>
-
<groupId>org.slf4j</groupId>
-
<artifactId>slf4j-api</artifactId>
-
<version>${slf4j.version}</version>
-
</dependency>
-
<dependency>
-
<groupId>org.slf4j</groupId>
-
<artifactId>slf4j-log4j12</artifactId>
-
<version>${slf4j.version}</version>
-
</dependency>
-
<!-- log end -->
-
<!-- 映入JSON -->
-
<dependency>
-
<groupId>org.codehaus.jackson</groupId>
-
<artifactId>jackson-mapper-asl</artifactId>
-
<version>1.9.13</version>
-
</dependency>
-
<dependency>
-
<groupId>com.fasterxml.jackson.core</groupId>
-
<artifactId>jackson-databind</artifactId>
-
<version>2.1.0</version>
-
</dependency>
-
<dependency>
-
<groupId>com.fasterxml.jackson.core</groupId>
-
<artifactId>jackson-annotations</artifactId>
-
<version>2.1.0</version>
-
</dependency>
-
<!-- 上传组件包 -->
-
<dependency>
-
<groupId>commons-fileupload</groupId>
-
<artifactId>commons-fileupload</artifactId>
-
<version>1.3.1</version>
-
</dependency>
-
<dependency>
-
<groupId>commons-io</groupId>
-
<artifactId>commons-io</artifactId>
-
<version>2.4</version>
-
</dependency>
-
<dependency>
-
<groupId>commons-codec</groupId>
-
<artifactId>commons-codec</artifactId>
-
<version>1.9</version>
-
</dependency>
-
<!-- <dependency>
-
<groupId>junit</groupId>
-
<artifactId>junit</artifactId>
-
<version>4.11</version>
-
<!– 表示开发的时候引入,发布的时候不会加载此包 –>
-
<scope>test</scope>
-
</dependency>-->
-
<!--Spring test相关依赖-->
-
<dependency>
-
<groupId>org.springframework</groupId>
-
<artifactId>spring-test</artifactId>
-
<version>4.1.7.RELEASE</version>
-
</dependency>
-
<dependency>
-
<groupId>junit</groupId>
-
<artifactId>junit</artifactId>
-
<version>RELEASE</version>
-
</dependency>
-
<dependency>
-
<groupId>org.jsoup</groupId>
-
<artifactId>jsoup</artifactId>
-
<version>1.8.1</version>
-
</dependency>
-
<dependency>
-
<groupId>net.sourceforge.htmlunit</groupId>
-
<artifactId>htmlunit</artifactId>
-
<version>2.15</version>
-
</dependency>
-
<dependency>
-
<groupId>org.seleniumhq.selenium</groupId>
-
<artifactId>selenium-java</artifactId>
-
<version>2.33.0</version>
-
</dependency>
-
<dependency>
-
<groupId>us.codecraft</groupId>
-
<artifactId>webmagic-core</artifactId>
-
<version>0.6.1</version>
-
</dependency>
-
<dependency>
-
<groupId>us.codecraft</groupId>
-
<artifactId>webmagic-extension</artifactId>
-
<version>0.6.1</version>
-
</dependency>
-
</dependencies>
-
<!-- <build>
-
<finalName>hugo</finalName>
-
<resources>
-
<resource>
-
<directory>src/main/java</directory>
-
<includes>
-
<include>**/*.xml</include>
-
</includes>
-
<filtering>true</filtering>
-
</resource>
-
</resources>
-
</build>-->
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.tomcat.maven</groupId>
-
<artifactId>tomcat7-maven-plugin</artifactId>
-
<version>2.2</version>
-
<configuration>
-
<!-- 端口 -->
-
<port>8081</port>
-
<!-- 上下文路径 "/" 表示没有 -->
-
<path>/ssmDemeTwo</path>
-
<!-- 忽略war包,tomcat打包会检查项目是否已经变成war,但是对于插件而言不需要打成war包 -->
-
<ignorePackaging>true</ignorePackaging>
-
</configuration>
-
</plugin>
-
</plugins>
-
<finalName>hugo</finalName>
-
<resources>
-
<resource>
-
<directory>src/main/java</directory>
-
<includes>
-
<include>**/*.xml</include>
-
</includes>
-
</resource>
-
<resource>
-
<directory>src/main/resources</directory>
-
<includes>
-
<include>*.*</include>
-
</includes>
-
</resource>
-
</resources>
-
</build>
-
</project>
五、idea的配置:
1、maven配置
2、为了防止idea抽风说jdk识别有误
3、为项目添加web包
maven的好处:自动下载jar包,不必手动寻找添加进入lib,
pom.xml 配置即可!
4、添加spring识别(如果已经识别,则不用手动了)
5、配置跑起项目
运行后,打开网址输入:localhost:8081/ssmDemoTwo即可看到hello word