|
From: Bill B. <bb...@re...> - 2013-01-21 18:39:16
|
i DON'T KNOw, maybe spring has already initialized after you registered
the processors?
On 1/21/2013 1:04 PM, Fritz Richter wrote:
> Hi everybody,
> it is so frustrating so I hope you are able to help me with my current
> problem.
>
> I have got the following technology stack:
>
> - Spring 3.1
> - Servlet 3 environment
> - Resteasy
>
> I want to raise up a Resteasy Rest API as a second Servlet. The beans
> are configured in my root context. In our project we are not using the
> web.xml nor any xml-configuration but
> configuring everything via a WebApplicationInitializer (Servlet 3).
>
> The problem is, that the usual way is to use the XML approach, where the
> SpringContextLoaderListener does not extend the new Constructor, which
> takes the root context.
>
> I tried to use the following approach:
>
> public abstract class AbstractWebAppInitializer implements
> WebApplicationInitializer {
> @Override
> public void onStartup(ServletContext servletContext) throws
> ServletException {
> servletContext.addListener(new ResteasyBootstrap());
> servletContext.addListener(new ContextLoaderListener(getRootContext()));
> initResteasy(servletContext);
> }
> ...
> private void initResteasy(ServletContext servletContext) {
> ResteasyProviderFactory providerFactory = (ResteasyProviderFactory)
> servletContext.getAttribute(ResteasyProviderFactory.class.getName());
> if (providerFactory == null) throw new RuntimeException(
> "RESTeasy Provider Factory is null, do you have the ResteasyBootstrap
> listener configured?");
>
> Registry registry = (Registry)
> servletContext.getAttribute(Registry.class.getName());
> if (registry == null) throw new RuntimeException(
> "RESTeasy Registry is null, do ou have the ResteasyBootstrap listener
> configured?");
>
> Dispatcher dispatcher = (Dispatcher)
> servletContext.getAttribute(Dispatcher.class.getName());
> if (dispatcher == null) throw new RuntimeException(
> "RESTeasy Dispatcher is null, do ou have the ResteasyBootstrap listener
> configured?");
>
> SpringBeanProcessor processor = new SpringBeanProcessor(dispatcher,
> registry, providerFactory);
> getRootContext().addBeanFactoryPostProcessor(processor);
> getRootContext().addApplicationListener(processor);
> }
> }
>
> What basically happens is, that in the first step the Resteasy beans are
> registered in the servletContext, and later they should be used as
> BeanPostProcessors, I guess that the Postprocessor is searching
> for jax-rs annotated beans, so they can be exposed via Resteasy.
>
> But my solution is not working, as to the time of the initResteasy()
> call, the beans are not registered already.
>
> There there anybody, who was able to use Resteasy in such a Servlet3
> configuration already?
>
> Thanks so much in advance.
>
> P.S. The reason for my approach is, that I tried to switch from Jersey
> to Resteasy, as Jesey made a lot of trouble with different versions etc.
> And I do not want to use Springs default Rest implementation, as jax-rs
> is pretty straight forward.
>
>
>
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122412
>
>
>
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|