【问题标题】:Can not start Spring application in tomcat with maven plugin无法使用 maven 插件在 tomcat 中启动 Spring 应用程序
【发布时间】:2023-03-29 22:40:02
【问题描述】:

我使用 Maven Tomcat 插件运行 maven 目标“全新安装”:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>

    <configuration>
        <url>http://localhost:8080/manager/html</url>
        <server>TomcatServer</server>
        <failOnError>false</failOnError>
        <path>/spring-training</path>
        <fork>true</fork>
    </configuration>
    <executions>
        <execution>
            <id>01-start-tomcat</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>02-stop-tomcat</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>shutdown</goal>
            </goals>
        </execution>
    </executions>
</plugin>

并得到错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logBeanFactoryPostProcessor' defined in URL [jar:file:/D:/projects/MainSpringProject/SpringSubProject/General/target/General-1.0-SNAPSHOT.jar!/com/springproject/ioc/LogBeanFactoryPostProcessor.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot resolve reference to bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' while setting bean property 'transactionAttributeSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: com.noveogroup.springtrainig.service.ApplicationService [Xlint:invalidAbsoluteTypeName]

请注意如果我运行 maven "clean package" 并手动部署到 tomcat 中没有 没有错误!,但是当我使用 tomcat-maven-插件我得到这样的错误。可能是什么问题?

【问题讨论】:

  • 你似乎有多个模块,所以我怀疑从 maven 部署时有不同的类路径(旧的、不完整的等)。可以分享一下完整的 maven 配置吗?

标签: java spring maven tomcat plugins


【解决方案1】:

我建议从更简单(且更新的)配置开始:

  <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <configuration>
      <port>9090</port>
      <useTestClasspath>true</useTestClasspath>
      <path>/</path>
    </configuration>
  </plugin>

那么你应该可以使用命令行启动tomcat了:

mvn tomcat7:run

请注意,这会启动一个嵌入式 tomcat 服务器,从而确保您不依赖于您可能在构建机器上安装 Tomcat 的位置。

【讨论】:

    猜你喜欢
    • 2015-11-02
    • 2023-03-07
    • 2022-07-26
    • 2017-03-09
    • 1970-01-01
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    相关资源
    最近更新 更多