Jetty无法启动war文件

时间:2017-03-09 13:12:21

标签: java spring maven jetty war

我有一个maven spring boot应用程序,我成功打包了Intellij的war文件。对于测试我在本地运行jetty并将war文件放在webapps目录中但是我收到此错误:

  

/ hallo ---> oejwWebAppContext @ 6c86e993 {/喂,[文件:/// C:/Users/ricardo/AppData/Local/Temp/jetty-0.0.0.0-8080-hallo.war-_hallo-any-3522993186615732718.dir/webapp/,罐子:文件:/// C:/Users/ricardo/AppData/Local/Temp/jetty-0.0.0.0-8080-hallo.war-_hallo-any-3522993186615732718.dir/webapp/WEB-INF/lib/jquery- 3.1.1.jar!/ META-INF / resources,jar:file:/// C:/Users/ricardo/AppData/Local/Temp/jetty-0.0.0.0-8080-hallo.war-_hallo-any-3522993186615732718 .dir / webapp / WEB-INF / lib / bootstrap-3.3.7.jar!/ META-INF / resources,jar:file:/// C:/Users/ricardo/AppData/Local/Temp/jetty-0.0。 0.0-8080-hallo.war-_hallo-任何-3522993186615732718.dir / web应用/ WEB-INF / LIB /自举-3.3.7-1.jar / META-INF /资源],UNAVAILABLE} {C:!\用户\ ricardo \ Desktop \ New folder \ webapps \ hallo.war} [失败]

这个名字现在是hallo.war。我的引导罐有什么问题吗?这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demoshop</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>

<name>demoshop</name>
<description>tool</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-bom</artifactId>
            <version>1.11.22</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <version>4.1.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-route53</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>   
        <version>2.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.7-1</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.10</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

如果您需要更多信息我可以提供。

更新 14-03:我在启动war文件时出错:

  

2017-03-14 12:05:59.772 INFO 6184 --- [Scanner-0] trationDelegate $ BeanPostProcessorChecker:类型为[class org.springframework.transaction.annotation]的Bean'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' .ProxyTransactionManagementConfiguration $$ EnhancerBySpringCGLIB $$ 344f3674]不适合所有BeanPostProcessors处理(例如:不符合自动代理条件)   2017-03-14 10:03:51.288 INFO 4468 --- [主要]   o.s.b.w.servlet.ServletRegistrationBean:映射servlet:   'dispatcherServlet'改为[/]

     

2017-03-14 10:03:51.291 INFO 4468 --- [
  main] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   'errorPageFilter'改为:[/ *]

     

2017-03-14 10:03:51.292 INFO 4468 --- [
  main] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   'characterEncodingFilter'为:[/ ]   2017-03-14 10:03:51.292 INFO 4468   --- [main] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter'到:[/ ]

     

2017-03-14 10:03:51.292 INFO 4468 --- [主要]   o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:   'httpPutFormContentFilter':[/ ] 2017-03-14 10:03:51.293 INFO 4468   --- [main] o.s.b.w.servlet.FilterRegistrationBean:映射过滤器:'requestContextFilter'到:[/ ]

     

2017-03-14 10:03:51.402 WARN 4468 --- [主要]   ationConfigEmbeddedWebApplicationContext:遇到异常   在上下文初始化期间 - 取消刷新尝试:   org.springframework.beans.factory.UnsatisfiedDependencyException:   使用名称创建bean时出错   'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':   通过构造函数参数0表示的不满意的依赖性;   嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   在类路径资源中定义名为'dataSource'的bean   [组织/ springframework的的/ boot /自动配置/ JDBC / DataSourceConfiguration $ Tomcat.class]:   通过工厂方法进行Bean实例化失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:失败   instantiate [org.apache.tomcat.jdbc.pool.DataSource]:工厂方法   'dataSource'抛出异常;嵌套异常是   java.util.ServiceConfigurationError:org.apache.juli.logging.Log:   提供者org.eclipse.jetty.apache.jsp.JuliLog不是子类型

     

2017-03-14 10:03:51.411 INFO 4468 --- [main] utoConfigurationReportLoggingInitializer:

UPADTE POM.xml:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-el</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7-1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.30</version>
        </dependency>
    </dependencies>

enter image description here

4 个答案:

答案 0 :(得分:2)

您可以像这样

从Jar中排除默认的Tomcat Embedded
  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-el</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

然后你应该包括码头

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

使用 mvn spring-boot:run 运行应用程序 希望这会有所帮助。

答案 1 :(得分:1)

来自Spring Boot文档 - Create a deployable war file

如果你想在应用服务器上运行,你需要这样的东西

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

}

答案 2 :(得分:0)

如果您使用Web依赖项,则无需部署Spring Boot应用程序,它将自动为您嵌入Tomcat以及所有依赖项。使用jar包装,您可以使用java:java -jar yourapp.java

直接运行它

答案 3 :(得分:0)

我在应用程序中更改了使用jetty生成war文件:

包含指南的应用程序类:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
    }

public static void main(String[] args) throws Exception {
    SpringApplication.run(Application.class, args);
    }

}

在许多人的帮助下,我将以下内容包含在我的pom文件中:

<packaging>war</packaging>

<properties>
    <jetty.version>9.1.0.v20131115</jetty.version>
    <servlet-api.version>3.1.0</servlet-api.version>
</properties>

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-juli</artifactId>
        <version>9.0.0.M17</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator</artifactId>
        <version>0.30</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

感谢您的帮助。