英文:
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命令进行部署。使用命令行参数传递数据库凭据。按照以下步骤进行操作,但部署失败。
- 安装了Maven和Tomcat 9。
- 在tomcat-users.xml中添加了一个具有manager-script角色的用户
<user username="role-user" password="role-pwd" roles="manager-script"/>
- 在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>
- 运行部署命令 -
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.
- Installed Maven and Tomcat 9.
- Added a user in tomcat-users.xml with role manager-script
<user username="role-user<" password="role-pwd" roles="manager-script"/>
- Added the plugin in 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>
- 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 'dataSource' 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
部分。
然后通过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
<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>
<systemProperties>
<db.user>${db.user}</db.user>
<db.pwd>${db.pwd}</db.pwd>
</systemProperties>
</configuration>
</plugin>
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
<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>
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 ["http-bio-8080"]
App is deployed and can be checke on the browser at localhost:8080/abc
If need to change port(eg-8081) add <port>8081</port>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论