weblogic服务器上部署的java spring引导中的html字符转义问题它在测试环境中工作,但在生产环境中不工作

i7uq4tfw  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(229)

在我的spring启动应用程序中,我有下面的代码,其中包含annotationconfigwebapplicationcontext,并且我在annotationconfigwebapplicationcontext中包含了frameworkwebconfig类(来自jar文件),该类用于在json响应中转义特殊字符。但对于某些问题,我不得不删除frameworkwebconfig类,然后在json响应中(正如预期的那样,在测试环境中)没有特殊字符转义。当我在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"
    //compile files('../csqt-java-framework/build/libs/framework.jar')
    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'
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题