环境:Window10(默认语言为英文)
springframeworl 4.3.0.RELEASE
控制台mvn tomcat7:run启动项目
pom.xml关键部分
4.3.0.RELEASE
UTF-8
javax.servlet
servlet-api
2.5
provided
org.odata4j
odata4j-jersey
0.7.0
org.apache.commons
commons-lang3
3.0
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-core
${org.springframework.version}
org.springframework
spring-aop
${org.springframework.version}
org.springframework
spring-beans
${org.springframework.version}
org.springframework
spring-webmvc
${org.springframework.version}
org.springframework
spring-web
${org.springframework.version}
org.springframework
spring-orm
${org.springframework.version}
org.springframework.data
spring-data-jpa
1.11.6.RELEASE
org.springframework.data
spring-data-rest-webmvc
2.6.6.RELEASE
org.springframework
spring-aspects
${org.springframework.version}
org.springframework.hateoas
spring-hateoas
0.23.0.RELEASE
org.apache.activemq
activemq-all
5.9.0
org.springframework
spring-jms
${org.springframework.version}
org.springframework
spring-jms
${org.springframework.version}
org.apache.activemq
activemq-all
5.9.0
org.apache.xbean
xbean-spring
3.7
org.springframework
spring-test
${org.springframework.version}
test
junit
junit
4.12
test
org.mockito
mockito-all
1.9.5
test
org.powermock
powermock-module-junit4
${powermock.version}
test
org.powermock
powermock-api-mockito
${powermock.version}
test
axis
axis
1.4
org.apache.axis
axis-jaxrpc
1.4
org.apache.ws.commons.axiom
axiom-api
1.2.20
org.apache.axis2
axis2-adb
1.5
org.apache.ws.commons.axiom
axiom-impl
1.2.20
runtime
commons-lang
commons-lang
2.4
org.apache.olingo
olingo-odata2-api
${olingo.version}
org.apache.olingo
olingo-odata2-core
${olingo.version}
javax.ws.rs
javax.ws.rs-api
io.springfox
springfox-swagger2
2.6.1
com.michaelwflaherty
cleverbotapi
1.0.2
org.apdplat
word
1.3
maven-war-plugin
2.1
${project.artifactId}
maven-compiler-plugin
2.5.1
1.8
true
true
org.apache.tomcat.maven
tomcat7-maven-plugin
2.0
${project.basedir}/src/test/resources/context.xml
org.apache.activemq.tooling
activemq-perf-maven-plugin
5.9.0
这里因为activemq带了slf4j,org.spdlat中引入了slf4j-api和logback-classic,所以不需要另外引入slf4j和log4j,如果需要的话引入slf4j-api
运行项目显示绑定的是log4j
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/i332390/.m2/repository/org/apache/activemq/activemq-all/5.9.0/activemq-all-5.9.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/i332390/.m2/repository/ch/qos/logback/logback-classic/0.9.28/logback-classic-0.9.28.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Sep 27, 2017 4:39:27 PM org.apache.catalina.core.ApplicationContext log
在src/main/resources下创建log4j.xml (appender的encoding为第一个关键点)
使用时引入 org.slf4j.Logger和org.slf4j.LoggerFactory
private static final Logger logger = LoggerFactory.getLogger(YourClass.class.getName());
logger.info("输出");
cmd控制台执行
chcp 65001
设置属性,选择合适的字体,比如
这时可以看到编码
对于http请求的中文乱码,设置Content-Type为application/json;charset=UTF-8
对于http回复的中文乱码,在servlet配置中可以这样写
参考链接:
http://blog.csdn.net/lixiaolong521999/article/details/70046489
http://www.cnblogs.com/edwardlauxh/archive/2010/07/22/1918554.html
https://my.oschina.net/huanger/blog/714179
http://blog.csdn.net/inkfish/article/details/4761357
http://www.cnblogs.com/guogangj/p/3931397.html
http://blog.csdn.net/lansetiankong12/article/details/52512095
https://stackoverflow.com/questions/40922522/how-do-i-properly-include-the-org-apache-catalina-filters-setcharacterencodingf
http://blog.csdn.net/simon_1/article/details/9092747
http://blog.csdn.net/kontrol/article/details/7767983