Servlet在启动时未加载 [英] Servlet not loading on startup

查看:83
本文介绍了Servlet在启动时未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:<load-on-startup>似乎没有导致我的Jersey Web服务在启动时加载

TL;DR: <load-on-startup> does not seem to be causing my Jersey web services to load on startup

我正在尝试建立一个简单的RESTful Web服务,该服务将充当容器中其他RESTful服务的注册表. 为此,我计划在静态初始化块中将其他Web服务与注册表服务一起注册.一切都进行得很顺利,直到我想起servlet直到第一次访问才加载. 快速的Web搜索打开了<load-on-startup>标记,该标记可以添加到web.xml中的servlet定义中.不幸的是,这已经在我的配置中设置了,并向静态块中添加了一些日志记录,以验证这些类确实在每次访问每个服务之前都没有加载.

I’m trying to set up a simple RESTful web service that will act as a registry for the other RESTful services in the container. To do this I had planned on registering each other web service with the registry service in a static initialize block. Everything was going well until I remembered that servlets aren’t loaded until their first access. A quick web search turned up the <load-on-startup> tag that can be added to the servlet definition in web.xml. Unfortunately, this was already set in my configuration and adding some logging to the static blocks verified that the classes were indeed not being loaded until the first access of each service.

我正在使用Jersey注释开发这些servlet,并将它们部署到Apache Tomcat(嵌入在netbeans中的7.0.22和远程部署的6.0.33都以相同的方式失败). 除了这种可感觉到的不当行为之外,这些servlet还在正确执行.

I’m developing these servlets using Jersey annotations and deploying them to Apache Tomcat (both 7.0.22 embedded in netbeans and 6.0.33 deployed remotely fail in the same way). Besides this perceived misbehavior, the servlets have been performing correctly.

关于我可能做错了什么的任何想法?

Any ideas on what I could be doing wrong?

我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <filter>
        <filter-name>CORSFilter</filter-name>
        <filter-class>com.foo.bar.CORSFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CORSFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
        <init-param>
            <description>Multiple packages, separated by semicolon(;), can be specified in param-value</description>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.foo.bar.webservices</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>redirect.jsp</welcome-file>
    </welcome-file-list>
</web-app>

推荐答案

它是几年前的事,后来又是Java Web Stack的学问了.

It was a couple years ago and a couple years of Java Web Stack knowledge later.

我认为这是身份错误的情况.我有一个非容器管理的资源,试图在启动时加载.如web.xml所指定的那样,最确定地在启动时加载jersey servlet容器.容器本身未引用我要预加载的类,因此未随容器一起加载.

I believe this was a case of mistaken identity. I had a non container managed resource that I was trying to get to load on startup. The jersey servlet container was most assuredly loading on start up as the web.xml was specifying. The classes that I wanted to preload were not being referenced by the container itself so were not being loaded with the container.

这篇关于Servlet在启动时未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆