From: Steven S. <ssc...@op...> - 2016-04-20 01:52:29
|
[ this is a cross-post of a StackOverflow question: https://stackoverflow.com/questions/36730237/integrating-spring-boot-with-resteasy ] I am looking for guidance integrating RESTEasy with Spring boot. Almost all of the documentation I have found is for very old Spring versions (2.x) with "web.xml" setup, and I want to go pure Java config. I'm surprised at how difficult and undocumented this task is :( I found the docs here: https://docs.jboss.org/resteasy/docs/3.0.16.Final/userguide/html/RESTEasy_Spring_Integration.html which indicate that I should install the ResteasyBootstrap, SpringBeanProcessorServletAware, and HttpServletDispatcher. So I write a Configuration class like this: @Configuration @Import({ResteasyBootstrap.class, SpringBeanProcessorServletAware.class, HttpServletDispatcher.class}) public class EmbeddedJetty { @Bean @Singleton public EmbeddedServletContainerFactory servletContainer() { JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(); factory.setPort(9000); factory.setSessionTimeout(10, TimeUnit.MINUTES); return factory; } } The ResteasyBootstrap and HttpServletDispatcher get wired up just fine. But bringing in the SpringBeanProcessorServletAware causes things to blow up: java.lang.NullPointerException: null at org.jboss.resteasy.plugins.spring.SpringBeanProcessorServletAware.getRegistry(SpringBeanProcessorServletAware.java:30) at org.jboss.resteasy.plugins.spring.SpringBeanProcessor.postProcessBeanFactory(SpringBeanProcessor.java:247) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:680) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) If it's not present, the app comes up, but none of the resources are detected and so request routing fails miserably. I suspect this is some sort of ordering problem -- the SpringBeanProcessorServletAware class tries to access its Registry before the ServletContextAware interface gets the ServletContext injected. But I've no clue how to fix this! What's the correct incantation to wire RESTEasy into Jetty / Spring Boot? I am running RESTEasy 3.0.16, Spring Boot 1.3.3, Spring Framework 4.3.0.RC1 Thanks for any guidance, Steven |