찾다

 >  Q&A  >  본문

java - Jetty启动不加载WEB-INF/lib下的JAR

Jetty启动不加载WEB-INF/lib下的JAR

直接使用java启动下面的main函数,发现Jetty没有到WEB-INF/lib下面的JAR。代码如下:

/**
 * 启动器
 */
public class Launcher {
    public static void main(String args[]) throws Exception {
        new Launcher().start();
    }

    void start() throws Exception {
        // 服务器的监听端口
        Server server = new Server(80);
        // 关联一个已经存在的上下文
        WebAppContext context = new WebAppContext();
        // 设置描述符位置
        String path = Launcher.class.getResource("/").getPath();
        context.setDescriptor(path + "../web.xml");
        // 设置Web内容上下文路径
        context.setResourceBase(path + "/../../");
        // 设置上下文路径
        context.setContextPath("/admin/");
        context.setParentLoaderPriority(true);
        //开启HTML,CSS,JS热部署
        context.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        server.setHandler(context);
        // 启动
        server.start();
        server.join();
    }
}

错误日志:

2016-06-05 17:01:13.080 [main] ERROR o.s.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addressConsigneeIo' defined in file [D:\Project\CORP\EP\netease-ep\trunk\WebContent\WEB-INF\classes\org\darkgem\io\address\AddressConsigneeIo.class]: Post-processing failed of bean type [class org.darkgem.io.address.AddressConsigneeIo] failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [org.darkgem.io.address.AddressConsigneeIo] for resource metadata: could not find class that it depends on
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:940)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:640)
    at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:419)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:875)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:348)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1379)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:774)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.server.Server.start(Server.java:405)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.server.Server.doStart(Server.java:372)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.darkgem.jetty.Launcher.start(Launcher.java:31)
    at org.darkgem.jetty.Launcher.main(Launcher.java:11)
Caused by: java.lang.IllegalStateException: Failed to introspect bean class [org.darkgem.io.address.AddressConsigneeIo] for resource metadata: could not find class that it depends on
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:334)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:935)
    ... 34 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/jdbc/core/JdbcTemplate;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:710)
    at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:652)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.buildResourceMetadata(CommonAnnotationBeanPostProcessor.java:351)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:330)
    ... 36 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.core.JdbcTemplate
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 43 common frames omitted
PHP中文网PHP中文网2802일 전826

모든 응답(2)나는 대답할 것이다

  • 天蓬老师

    天蓬老师2017-04-18 09:08:36

    시작할 때 java -cp jetty.jar;WebContentWEB-INFclasses Launcher를 사용하여 프로젝트를 시작하세요.

    오류 로그를 보면 org.springframework.core.JdbcTemplate 클래스를 찾을 수 없다는 것을 알 수 있습니다. 문제의 소스코드는 아래 classes 비즈니스 코드에 있습니다.

    그래서 하나가 형성되었습니다:

    으아악

    에는 이러한 종속성 구조가 있으므로 Spring 컨테이너를 초기화할 때 AppCloassLoader에서 클래스를 초기화하면(Spring에 따라) Spring 클래스 JdbcTemplate를 쿼리할 수 없다는 것을 발견했습니다. 이는 로더의 双亲委托机制 때문입니다.

    해결책:

    1. 시작 시 모든 libs와 jar 지정

    2. 또는 강제 지정, jetty Launcher 시작으로 로드된 클래스 경로를 사용하지 마세요: context.setParentLoaderPriority(false);

    3. start.jar과 같은 캡슐화된 부두 실행 프로그램을 사용하여 시작할 때 특정 classpath

    4. 을 지정해야 합니다.
    으아악

    회신하다
    0
  • PHP中文网

    PHP中文网2017-04-18 09:08:36

    설정해 보셨나요context.setExtraClasspath(你的WEB-INF/lib)?

    회신하다
    0
  • 취소회신하다