部署应用程序在上下文路径 [/abc],但上下文启动失败 – Maven Spring 项目问题

huangapple go评论108阅读模式
英文:

Deployed application at context path [/abc] but context failed to start - Maven Spring Project Issue

问题

我有一个部署在AWS Beanstalk上的Maven Spring Web应用程序,运行良好。现在,我想将其迁移到OCI VPS/VM,并使用tomcat7-maven-plugin通过maven命令进行部署。使用命令行参数传递数据库凭据。按照以下步骤进行操作,但部署失败。

  1. 安装了Maven和Tomcat 9。
  2. tomcat-users.xml中添加了一个具有manager-script角色的用户
<user username="role-user" password="role-pwd" roles="manager-script"/>
  1. 在pom.xml中添加了插件
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://localhost:8080/manager/text</url>
        <username>role-user</username>
        <password>role-pwd</password>
        <path>/abc</path>
        <update>true</update>
    </configuration>
</plugin>
  1. 运行部署命令 - mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:deploy

它将WAR文件上传到/webapps,然后出现以下错误消息:FAIL - Deployed application at context path [/abc] but context failed to start

我在本地也尝试了一下,以为可能需要在VM上进行一些额外的配置,但没有成功。

日志中显示找不到db.user属性,因此由于某种原因无法读取命令行参数。

Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Could not resolve placeholder

在尝试上述步骤之前,我尝试通过Tomcat UI上传WAR文件,但由于不知道如何传递附加参数或是否可能传递附加参数,所以没有成功。

如果有人能够帮助解决这两种方法中的任何一种,将不胜感激。

谢谢!

PS- 我不是Java开发人员,这是我偶尔工作的一个副项目,我上次在项目中使用Java/Tomcat已经超过7年了。所以,也许有一个愚蠢的错误或直接的解决方案,我不知道。

英文:

I have a maven spring web-app which is deployed on AWS Beanstalk and working fine. Now, I want to shift it to OCI VPS/VM and use tomcat7-maven-plugin to deploy using the maven command. Using command line args to pass DB credentials. followed the below steps but deployment is failing.

  1. Installed Maven and Tomcat 9.
  2. Added a user in tomcat-users.xml with role manager-script
&lt;user username=&quot;role-user&lt;&quot; password=&quot;role-pwd&quot; roles=&quot;manager-script&quot;/&gt;
  1. Added the plugin in pom.xml
&lt;plugin&gt;
     &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
     &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
     &lt;version&gt;2.2&lt;/version&gt;
     &lt;configuration&gt;
         &lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt;
		 &lt;username&gt;role-user&lt;/username&gt;
		 &lt;password&gt;role-pwd&lt;/password&gt;
         &lt;path&gt;/abc&lt;/path&gt;
		 &lt;update&gt;true&lt;/update&gt;
     &lt;/configuration&gt;
&lt;/plugin&gt;
  1. Ran the command to deploy - mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:deploy

It uploads the WAR in /webapps then fails with this message FAIL - Deployed application at context path [/abc] but context failed to start.

I tried it on my local also, thinking maybe the setup on VM needs some additional config, didn't work.

In the logs, it says db.user property not found, so not able to read command line args for some reason.

Invalid bean definition with name &#39;dataSource&#39; defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Could not resolve placeholder

Before trying the above steps, I tried to upload the WAR file via the Tomcat UI and it didn't work because I don't know how to pass additional args there or if it is even possible.

If someone can help with either of those approaches it would be much appreciated.

TIA

PS - I am not a Java developer and this is a side project I work on sometimes, last time I used java/tomcat in a project was more than 7 yrs ago. So, maybe there is a silly mistake or straight forward solution and I am not aware of it.

答案1

得分: 1

mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:deploy

这个命令并不意味着war文件将使用这些系统属性(db.user, db.pwd)部署到一个tomcat虚拟机中。文档不够清晰(https://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html),但请查看systemProperties部分。

org.apache.tomcat.maven
tomcat7-maven-plugin
2.2

http://localhost:8080/manager/text
role-user role-pwd /abc true

${db.user}
${db.pwd}

然后通过mvn命令运行:

mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:deploy

希望这样能够正常工作。

英文:
mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:deploy

This command does not mean that war will be deployed in a tomcat VM with these system properties (db.user, db.pwd) The documentation is not good enough (https://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html) but look at the systemProperties section

&lt;plugin&gt;
 &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
 &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
 &lt;version&gt;2.2&lt;/version&gt;
 &lt;configuration&gt;
     &lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt;
     &lt;username&gt;role-user&lt;/username&gt;
     &lt;password&gt;role-pwd&lt;/password&gt;
     &lt;path&gt;/abc&lt;/path&gt;
     &lt;update&gt;true&lt;/update&gt;
     &lt;systemProperties&gt;
       &lt;db.user&gt;${db.user}&lt;/db.user&gt;
       &lt;db.pwd&gt;${db.pwd}&lt;/db.pwd&gt;
    &lt;/systemProperties&gt;
 &lt;/configuration&gt;
&lt;/plugin&gt;

And then run via mvn command:

mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:deploy

This should hopefully work.

答案2

得分: 0

经过一些调整后,我成功使其工作。

从插件详细信息中删除用户名、密码和URL。

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <path>/abc</path>
        <update>true</update>
        <systemProperties>
            <db.user>${db.user}</db.user>
            <db.pwd>${db.pwd}</db.pwd>
        </systemProperties>
    </configuration>
</plugin>

使用以下命令进行部署:
mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:run

它将启动自己的Tomcat容器,因此无需预先运行任何Tomcat实例或在tomcat-users.xml中创建任何用户。

一旦在终端/命令提示符中看到以下行:

Aug 10, 2023 11:49:25 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]

应用程序已部署,并可以在浏览器上通过localhost:8080/abc进行检查。

如果需要更改端口(例如8081),请在configuration标签下添加<port>8081</port>

但现在我对之前的工作原理很好奇,看到了许多帖子/博客。如果有人知道,请评论。

英文:

I was able to make it work after some tweaks

Remove username,password and url from plugin details

&lt;plugin&gt;
 &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
 &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
 &lt;version&gt;2.2&lt;/version&gt;
 &lt;configuration&gt;
     &lt;path&gt;/abc&lt;/path&gt;
     &lt;update&gt;true&lt;/update&gt;
     &lt;systemProperties&gt;
       &lt;db.user&gt;${db.user}&lt;/db.user&gt;
       &lt;db.pwd&gt;${db.pwd}&lt;/db.pwd&gt;
    &lt;/systemProperties&gt;
 &lt;/configuration&gt;
&lt;/plugin&gt;

Use the below command to deploy
mvn -Ddb.user=db-user -Ddb.pwd=db-pwd tomcat7:run

It will start its own tomcat container, hence is no need to run any instance of tomcat beforehand or create any user in tomcat-users.xml

Once you see the below lines on terminal/cmd

Aug 10, 2023 11:49:25 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [&quot;http-bio-8080&quot;]

App is deployed and can be checke on the browser at localhost:8080/abc

If need to change port(eg-8081) add &lt;port&gt;8081&lt;/port&gt; under configuration tag

But now I am curious about how the previous thing works, have seen many posts/blogs about that. If anybody knows, please comment.

huangapple
  • 本文由 发表于 2023年8月9日 17:31:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定