问题描述
在我的 Spring Boot 应用程序中,我有以下代码,其中包含 AnnotationConfigWebApplicationContext,并且我在 AnnotationConfigWebApplicationContext 中包含了 FrameworkWebconfig 类(来自 jar 文件),该类用于转义 JSON 响应中的特殊字符。但是对于某些问题,我不得不删除该框架 web 配置类,之后特殊字符没有在 JSON 响应中转义(正如预期的那样,在 TEST 环境中)。当我在 PROD 中运行时相同的代码它不起作用它仍在转义这些特殊字符。此应用程序部署在 Weblogic 服务器上。我不明白这里有什么问题。有人可以帮我理解为什么会这样吗?
@Configuration
public class Application implements WebApplicationInitializer {
....
private AnnotationConfigWebApplicationContext getContext() {
logger.info("Entering method : getContext");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(FrameworkPropertySourcesConfig.class);
//context.register(FrameworkWebConfig.class); //this line,after removing its working in TEST but not in prod
context.register(AppConfig.class);
logger.info("Exiting method : getContext");
return context;
}
.....
}
@EnableWebMvc
@Configuration
public class FrameworkWebConfig extends WebMvcConfigurerAdapter {
private MappingJackson2HttpMessageConverter buildHtmlEscapingJsonConverter() {
MappingJackson2HttpMessageConverter htmlEscapingConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.getJsonFactory().setCharacterEscapes(new HTMLCharacterEscapes());
htmlEscapingConverter.setObjectMapper(objectMapper);
return htmlEscapingConverter;
}
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
converters.add(this.buildHtmlEscapingJsonConverter());
}
@Bean
CommonsMultipartResolver multipartResolver() {
return new CommonsMultipartResolver();
}
}
下面是 build.gradle 文件
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
}
}
plugins {
//id "org.sonarqube" version "2.5"
//gradle sonarqube
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
//apply plugin: 'org.sonarqube'
war {
baseName = 'CServices'
webInf { from 'WEB-INF' }
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
configurations {
providedRuntime
providedCompile
exclude
jar
}
dependencies {
compile files('WEB-INF/lib/framework.jar')
compile files('WEB-INF/lib/wsclient.jar')
compile("org.springframework.boot:spring-boot-starter-redis")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.security.oauth:spring-security-oauth2:2.0.7.RELEASE")
compile("org.springframework.boot:spring-boot-starter-thymeleaf"){
exclude module: 'spring-boot-starter-tomcat'
}
compile("org.springframework.boot:spring-boot-starter-web"){
exclude module: 'spring-boot-starter-tomcat'
}
compile("org.springframework.ws:spring-ws-core")
compile("org.springframework:spring-tx")
compile("org.springframework:spring-jdbc")
compile("org.mybatis:mybatis:3.2.8")
compile("org.mybatis:mybatis-spring:1.2.3")
compile('org.springframework.boot:spring-boot-starter-mail')
compile("org.apache.poi:poi:3.9")
compile("org.apache.poi:poi-ooxml:3.9")
compile('commons-httpclient:commons-httpclient:3.1')
compile("org.apache.commons:commons-lang3:3.1")
compile('org.hsqldb:hsqldb:2.0.0')
compile('commons-fileupload:commons-fileupload:1.2')
compile('commons-io:commons-io:1.4')
compile('com.google.code.gson:gson:2.2.4')
compile('com.google.guava:guava:r05')
compile("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1");
compile('org.json:json:20090211')
compile('org.projectlombok:lombok:1.18.10')
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
compile group: 'com.microsoft.sqlserver',name: 'mssql-jdbc',version: '6.1.0.jre7'
compile group: 'com.fasterxml.jackson.core',name: 'jackson-core',version: '2.9.0'
//compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.0"
testCompile("org.springframework.boot:spring-boot-starter-test")
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
compile group: 'org.springframework',name: 'spring-mock',version: '2.0.8'
compile group: 'org.springframework.boot',name: 'spring-boot-starter-aop',version: '1.2.5.RELEASE'
compile('commons-beanutils:commons-beanutils:1.9.2')
// https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui
compile group: 'io.springfox',name: 'springfox-swagger-ui',version: '2.9.2'
// https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
compile group: 'io.springfox',name: 'springfox-swagger2',version: '2.9.2'
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava',name: 'guava',version: '27.0-jre'
testCompile group: 'org.mockito',name: 'mockito-all',version: '1.8.4'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
wtp {
component {
contextPath = '/cs'
}
}
project{
natures 'org.springsource.ide.eclipse.gradle.core.nature'
}
}
//task afterEclipseImport { dependsOn ':cs-java-framework:jar' }
//compileJava.dependsOn ':cs-java-framework:jar'
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)