Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Using Spring inside Jetty

Hi,

On Fri, Jan 24, 2014 at 9:30 PM, Jim Garrison <jim.garrison@xxxxxxxx> wrote:
> Given this web.xml
>
>     <web-app
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>         xmlns="http://java.sun.com/xml/ns/javaee";
>         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd";
>         metadata-complete="false"
>         version="3.1">
>         <!-- Spring Context Parameters -->
>         <context-param>
>             <param-name>contextConfigLocation</param-name>
>             <param-value>classpath:/org/nwea/etl/spring/applicationContext-web.xml</param-value>
>         </context-param>
>         <listener>
>             <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>         </listener>
>     </web-app>
>
> and this applicationContext-web.xml
>
>     <?xml version="1.0" encoding="UTF-8"?>
>     <beans xmlns="http://www.springframework.org/schema/beans";
>            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>            xmlns:context="http://www.springframework.org/schema/context";
>            xsi:schemaLocation=
>             "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
>             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd";>
>
>         <bean id="quartzSchedulerFactory" class="org.quartz.impl.StdSchedulerFactory"/>
>         <bean id="coreScheduler" factory-bean="quartzSchedulerFactory" factory-method="getScheduler" init-method="start"/>
>         <bean id="helloServlet" class="org.nwea.etl.helloworld.HelloWorld"/>
>     </beans>
>
> With helloServlet defined as
>
>     @WebServlet(name="hello", urlPatterns={"/hello"})
>     public class HelloWorld extends HttpServlet
>     {
>         @Autowired
>         private Scheduler coreScheduler;
>         @Override
>         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
>         {
>             etc...
>
> The HelloWorld class gets instantiated and coreScheduler is injected by Spring,
> but then gets instantiated again by Jetty (without coreScheduler)
> when the client sends a GET /hello.
>
> Is there a way to configure Jetty to retrieve the servlet instance
> from Spring?

No. Jetty does not know about Spring.

> Is the correct solution to use Spring's DispatcherServlet in front of everything I want configured via Spring, or is there a more JEE-6 way to do this with Jetty?

You have metadata-complete=false in your web.xml.
This means that Spring will do its discovery, and then also Jetty will
do its discovery.

I would try to set metadata-complete=true, so that Jetty does not do
its discovery. There may be other things that needs to be done, but I
would try that first.

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.


Back to the top