Если вы строите ваш .war с spring-data, запускаете java -jar <path-to-war> --debug
, а затем собираете / запускаете его без spring-data и выводите результаты, вы можете видеть, что следующие bean-компоненты включаются, когдаДобавлены данные Spring.
SpringDataWebAutoConfiguration matched:
- @ConditionalOnClass found required classes 'org.springframework.data.web.PageableHandlerMethodArgumentResolver', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
- found ConfigurableWebEnvironment (OnWebApplicationCondition)
- @ConditionalOnMissingBean (types: org.springframework.data.web.PageableHandlerMethodArgumentResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
SpringDataWebAutoConfiguration#pageableCustomizer matched:
- @ConditionalOnMissingBean (types: org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer; SearchStrategy: all) did not find any beans (OnBeanCondition)
SpringDataWebAutoConfiguration#sortCustomizer matched:
- @ConditionalOnMissingBean (types: org.springframework.data.web.config.SortHandlerMethodArgumentResolverCustomizer; SearchStrategy: all) did not find any beans (OnBeanCondition)
Это потому, что данные Spring предоставляют контроллеры REST, которые ссылаются на ваши репозитории данных, как упомянуто здесь: http://spring.io/projects/spring-data-rest, и это нарушает автоматические конфигурации по умолчанию для сериализации объектов.передан в контроллеры REST.
Просто исключите автоматическую настройку, и ваша существующая автоматическая сериализация будет работать:
@SpringBootApplication(exclude = { SpringDataWebAutoConfiguration.class })
public class MyApplication{
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}