当前位置: 首页 > 知识库问答 >
问题:

当我导出到Jar时,嵌入式Derby服务器的Spring Boot无法工作

容宏逸
2023-03-14

当我导出到JAR时,嵌入式Derby服务器的Spring Boot无法工作。但当我在eclipse中运行该应用程序时,它可以正常工作。它只是当我导出它到jar时,当它不工作。

下面是我的POM https://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.0.release com.webups.spring app 0.0.1-snapshot app样板

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    <querydsl.version>4.2.1</querydsl.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <!-- JSON Web Token Support -->
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <!-- End JSON Web Token Support -->
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
   <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.6.2</version>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
    </dependency>
    <!-- io.springfox setup  -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.1</version>
        <scope>compile</scope>
    </dependency>
            <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>

            <dependencies>
                <dependency>
                    <groupId>com.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>4.1.2</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

下面是我的错误子容器在启动过程中失败

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@228605e1]
        at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_241]
        at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_241]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_241]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_241]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:468) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:437) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:191) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:176) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) [jar:rsrc:spring-context-5.2.6.RELEASE.jar!/:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [jar:rsrc:spring-boot-2.3.0.RELEASE.jar!/:na]
        at com.webupps.spring.app.AppApplication.main(AppApplication.java:14) [rsrc:./:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_241]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_241]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_241]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_241]
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58) [springbootswagger.jar:na]
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@228605e1]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:139) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:173) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4800) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4936) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_241]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_241]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        ... 35 common frames omitted
Caused by: java.lang.Error: factory already defined
        at java.net.URL.setURLStreamHandlerFactory(URL.java:1134) ~[na:1.8.0_241]
        at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.<init>(TomcatURLStreamHandlerFactory.java:130) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.getInstanceInternal(TomcatURLStreamHandlerFactory.java:53) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.register(TomcatURLStreamHandlerFactory.java:77) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.webresources.StandardRoot.registerURLStreamHandlerFactory(StandardRoot.java:700) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.webresources.StandardRoot.initInternal(StandardRoot.java:682) ~[jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136) [jar:rsrc:tomcat-embed-core-9.0.35.jar!/:na]
        ... 45 common frames omitted

共有1个答案

林德惠
2023-03-14

算了吧。只是个小错误。办法是这样的。

 类似资料:
  • 本文向大家介绍springboot工程jar包部署到云服务器的方法,包括了springboot工程jar包部署到云服务器的方法的使用技巧和注意事项,需要的朋友参考一下 首先,springboot在这里不多做介绍了,关于怎么打成jar包,我相信凡是用过的同学都知道吧! 然后就是将jar包上传到云服务器了,这个有好些工具的,博主在这里也不多做说明了! 咱们还是直奔主题吧。。。。 运行命令:java -

  • 运行Spring Boot应用程序时,嵌入式tomcat服务器无法启动。我刚刚在pom.xml中添加了所需的依赖项,并创建了一个简单的java POJO类。应用程序属性已经按照oracle数据库所需的jdbc配置以及Hibernate方言信息进行了设置。 执行mvn spring-boot:run时的控制台日志

  • 我一直试图启动服务器,但收到以下错误消息: 2013-01-23 19:24:18.133格林威治标准时间:使用基本服务器安全策略安装安全管理器。2013-01-23 19:24:18.430 GMT:无法侦听主机localhost:java上的端口1527。网BindException:无法分配请求的地址:JVM_Bind 最重要的是,我得到一个提示说: 无法连接。无法使用org.apache.

  • 我尝试将我的一个IntelliJ项目导出到.jar中,如果我在consol(java-jar name.jar)中运行.jar 它显示缺少JavaFX运行时,但这是必需的。如果我开始我的项目在IntelliJ它工作一切良好。 IntelliJ终极2020.1。 请耐心等待,这是我第一个自己的java项目和第一个fx应用程序, 也是我第一次尝试创建JAR。 我把一些设置的屏幕截图放在下面(链接)。

  • 我刚刚开始使用microservices,我想创建一个简单的Eureka服务器来执行我的Serviceregistry。目前,我只想在localhost上运行服务器,稍后我想添加一个注册到其中的示例微服务。问题是,我在尝试启动Eureka服务器时出错。我在Eclipse中使用Spring和Maven在ubuntu vm中开发。 我的POM. xml如下所示: http://maven.apache

  • 请帮帮我.我使用的是Ubuntu 16.04