解决在另一个Web服务中将Web服务用作Jar时发生的错误

时间:2018-12-03 09:51:36

标签: spring spring-boot tomcat jar war

我正在为我的公司开发Web Service,我有一个可以正常工作的Web Service,可以连接到数据库,并且需要将它作为Jar添加到另一个功能齐全的Web Service中。 我在第二个Web服务的pom中包含了第一个Web服务的执行程序Jar。当我通过IDE(STS)运行第二个Web服务时,它工作正常,但是当我创建第二个Web Service的War文件并尝试通过Apache Tomcat运行War文件时,会引发以下错误。

  

2018年12月3日12:58:16.190严重[http-nio-8090-exec-1]   org.apache.catalina.core.ApplicationContext.log失败-应用程序位于   上下文路径/gd-erp-1.0.0无法启动   org.apache.catalina.LifecycleException:无法启动组件   [StandardEngine [Catalina] .StandardHost [localhost] .StandardContext [/gd-erp-1.0.0]]     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)     在   org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1294)     在   org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:659)     在   org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:210)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:648)处   javax.servlet.http.HttpServlet.service(HttpServlet.java:729)在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)     在   org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:136)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)     在   org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:604)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)     在   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1152)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:684)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1539)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1495)     在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)     在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(未知源)造成原因:   org.springframework.beans.factory.UnsatisfiedDependencyException:   创建名称为“ aisleController”的bean时出错:不满意   通过字段“ userService”表示的依赖关系;嵌套异常为   org.springframework.beans.factory.UnsatisfiedDependencyException:   创建名称为'userService'的bean时出错:不满意的依赖关系   通过字段“ applicationService”表示;嵌套异常为   org.springframework.beans.factory.UnsatisfiedDependencyException:   创建名称为'applicationService'的bean时出错:不满意   通过字段“ userAssignmentServce”表示的依赖关系;嵌套的   例外是   org.springframework.beans.factory.UnsatisfiedDependencyException:   创建名称为'userAssignmentsService'的bean时出错:不满意   通过字段“ entityManager”表示的依赖关系;嵌套异常   是org.springframework.beans.factory.NoUniqueBeanDefinitionException:   没有类型为'javax.persistence.EntityManager'的合格Bean   可用:预期的单个匹配bean,但发现3:   org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2     在   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)     在   org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)     在   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1348)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:578)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)     在   org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)     在   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)     在   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)     在   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)     在   org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)     在   org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)     在   org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)     在   org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:327)     在   org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155)     在   org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:135)     在   org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)     在   org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5352)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)     ...另外32个

我的要求是要拥有一个可以正常运行的WebService,该WebService可以连接到数据库并像该WebService的一部分一样在第二个WebService中工作。

更新:添加了pom文件。

<?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>spring-boot-project</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>
    <name>spring-web-service</name>
    <description>Web Service using Spring boot</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.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>
    <dependencies>
        <!-- DevTools dependency - it makes server restart
 automatically(in 1-2           secs) within less time than manual restart
 takes(ie 10-20 sec). -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>            groupId>org.projectlombok
        </groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.2</version>
    </dependency>
    <!-- Model mapper library -->
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>2.3.1</version>
    </dependency>
    <!-- Swagger dependencies -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.7.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.7.0</version>
        <scope>compile</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <!--
 https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java
 -->
    <dependency>
        <groupId>com.mashape.unirest</groupId>
        <artifactId>unirest-java</artifactId>
        <version>1.4.9</version>
    </dependency>
    <!-- Log4j 2 Dependencies start -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.5</version>
        <!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.5</version>
        <!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <!--
 https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl
 -->
    <!-- <dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-jcl</artifactId><version>2.5</version>$NO-MVN-MAN-VER$ </dependency> -->
    <!--
 Log4j 2 Dependencies end -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- Dependencies for GreyDelta Utils -->
    <!--
 https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
        <!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <!--
 https://mvnrepository.com/artifact/org.apache.commons.io/commonsIO -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.2</version>
        <!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <!--
 https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
 -->
    <!-- <dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.11.0</version>$NO-MVN-MAN-VER$ </dependency> -->
    <!--
 https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <!--$NO-MVN-MAN-VER$ -->
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-orm</artifactId>
        <version>5.9.2.Final</version>
    </dependency>
    <!--
 https://mvnrepository.com/artifact/commons-logging/commons-logging -->
    <!-- <dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency> -->
</dependencies>
<!--    <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>  -->
    <build>
        <finalName>spring-web-service</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

请帮助。 谢谢。

0 个答案:

没有答案