Spring boot jackson转换不适用于本地环境

时间:2017-03-24 08:18:25

标签: spring spring-boot jackson

我有春季启动1.4.2应用程序。我使用的是杰克逊版本2.7.0。 当我用json作为请求调用任何POST api时。我在服务器日志中得到400作为响应代码,在响应正文中得到" fieldName:可能不是空的"作为该领域前面的信息。 此问题仅在本地环境中发生,并且在部署服务器环境中正常工作。 我尝试了所有可能的组合,如本地制作maven,java版本与服务器相同。但它没用。 本地操作系统是MAC,部署环境是LINUX。

Pom如下所示:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>

Spring boot主类如下所示:

@SpringBootApplication
@ImportResource({ "classpath:/META-INF/spring/applicationContext*.xml", "classpath:*-servlet.xml" })
@ComponentScan(basePackages = { "com.abc.test" })
public class MainApplication extends SpringBootServletInitializer {

    @Autowired
    Filter customRequestHeaderAuthenticationFilter;

    static final Logger LOGGER = LoggerFactory.getLogger(MainApplication.class);

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return configureApplication(builder);
    }

    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }

    private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
        return builder.sources(MainApplication.class).bannerMode(Banner.Mode.CONSOLE);
    }

    @Bean
    public ServletRegistrationBean remoteDispatcherRegistration(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
        registration.setName("remote");
        registration.addUrlMappings("/1.0/test/*");
        return registration;
    }

    @Bean
    public ServletRegistrationBean jsonDispatcherRegistration(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
        registration.setName("json");
        registration.addUrlMappings("/1.0/rest/*", "/1.1.1/rest/*", "/1.2/rest/*", "/rest/v1.2/*");
        return registration;
    }

    @Bean
    public ServletRegistrationBean xmlDispatcherRegistration(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
        registration.setName("xml");
        registration.addUrlMappings("/1.0/some/search");
        return registration;
    }

    @Bean
    public ServletRegistrationBean swaggerDispatcherRegistration(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
        registration.setName("swagger");
        registration.addUrlMappings("/api-docs", "/swagger-resources", "/swagger-ui.html");
        return registration;
    }

    @Bean
    public FilterRegistrationBean rewriteFilterConfig() {
        FilterRegistrationBean reg = new FilterRegistrationBean();
        //some filter related stuff
        return reg;
    }


    @Bean
    public FilterRegistrationBean customRqHdrAuthFilterConfig() {

        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(customRequestHeaderAuthenticationFilter);
        registration.addUrlPatterns("/*");
        registration.setName("customRequestHeaderAuthenticationFilter");
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ERROR);
        registration.setOrder(1);
        return registration;
    }
}

0 个答案:

没有答案