From: Jeff S. <js...@re...> - 2016-04-20 18:00:08
|
I posted an answer for you on SO with the configuration we use. http://stackoverflow.com/questions/36730237/integrating-spring-boot-with-resteasy/36750505#36750505 I too agree that it was far more difficult than it should be and it would be nice if RESTEasy would provide more first class support out of the box for the Spring ecosystem in general. Java EE is increasingly becoming irrelevant and RESTEasy wants to stay relevant it's going to need to embrace that reality. -----Original Message----- From: Steven Schlansker [mailto:ssc...@op...] Sent: Tuesday, April 19, 2016 4:19 PM To: res...@li... Subject: [Resteasy-developers] Integrating RESTEasy with Spring Boot [ 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 |