<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0modelVersion>
<groupId>test-mvcgroupId>
<artifactId>demo-mvcartifactId>
<packaging>warpackaging>
<version>0.0.1-SNAPSHOTversion>
<name>demo-mvc Maven Webappname>
<url>http://maven.apache.orgurl>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>3.8.1version>
<scope>testscope>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>4.3.5.RELEASEversion>
dependency>
dependencies>
<build>
<finalName>demo-mvcfinalName>
build>
project>
<web-app>
<display-name>Archetype Created Web Application demo_mvcdisplay-name>
<filter>
<filter-name>encodingfilter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
<init-param>
<param-name>encodingparam-name>
<param-value>UTF-8param-value>
init-param>
filter>
<filter-mapping>
<filter-name>encodingfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListenerlistener-class>
listener>
<servlet>
<servlet-name>demoservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>demoservlet-name>
<url-pattern>/url-pattern>
servlet-mapping>
web-app>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd
">
beans>
<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:util="http://www.springframework.org/schema/util"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<mvc:annotation-driven>mvc:annotation-driven>
<context:component-scan base-package="demo">context:component-scan>
<mvc:resources location="/resources/" mapping="/resources/**"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages">property>
<property name="suffix" value=".jsp">property>
bean>
beans>
package demo;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 参考示例
*/
@RestController
//@Order(value = 5)
public class ControllerExcample{
@RequestMapping("/tst")
public Object get_value(HttpServletRequest req) {
return "heihei";
}
}
<dependency>
<groupId>ch.qos.logbackgroupId>
<artifactId>logback-classicartifactId>
<version>1.1.7version>
dependency>
<configuration>
<property name="log_path" value="demo_logs"/>
<property name="maxHistory" value="30"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8charset>
<pattern>%d %p (%file:%line\)- %m%npattern>
encoder>
appender>
<appender name="console"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log_path}/console.logFile>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log_path}/console.log.%dfileNamePattern>
<maxHistory>${maxHistory}maxHistory>
rollingPolicy>
<encoder>
<pattern>
%d (%file:%line\)- %m%n
pattern>
encoder>
appender>
<appender name="baselog"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log_path}/base.logFile>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedR
ollingPolicy">
<fileNamePattern>${log_path}/base.log.%dfileNamePattern>
<maxHistory>${maxHistory}maxHistory>
rollingPolicy>
<encoder>
<pattern>
%d (%file:%line\)- %m%n
pattern>
encoder>
appender>
<appender name="userlog"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log_path}/user.logFile>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log_path}/user.log.%dfileNamePattern>
<maxHistory>${maxHistory}maxHistory>
rollingPolicy>
<encoder>
<pattern>
%d (%file:%line\)- %m%n
pattern>
encoder>
appender>
<root level="info">
<appender-ref ref="STDOUT" />
root>
<logger name="demo" level="debug">
<appender-ref ref="baselog" />
logger>
<logger name="USER">
<appender-ref ref="userlog" />
logger>
<jmxConfigurator/>
configuration>
package demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LogCore{
public static Logger BASE = LoggerFactory.getLogger(LogCore.class);
public static Logger USER = LoggerFactory.getLogger("USER");
}
在catalina路径也就是-Dcatalina.base=/Users/bao/data/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 参数
也就是System.getProperty(“user.dir”) 输出的地址
displayname 标签后添加
param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:applicationContext.xmlparam-value>
param>
servlet 的配置添加contextConfigLocation
<servlet>
<servlet-name>demo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>demo</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
这样打包的时候不打进去httpServlet,因为我们要将项目部署在Tomcat上,tomcat作为容器已经有这些jar了。
<dependency>
<groupId>javax.servletgroupId>
<artifactId>servlet-apiartifactId>
<version>2.5version>
<scope>providedscope>
dependency>
就跟Spring boot使用外部Tomcat的时候添加依赖一样
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-tomcatartifactId>
<scope>providedscope>
dependency>