当所有设置都正确时,Jenkins 自动部署失败。 -- mapperLocations 错误,Spring(illegalArgumentException,TomcatManagerException)
Jenkins auto deploying failed, when all settings are right. -- error in mapperLocations, Spring (illegalArgumentException, TomcatManagerException)
我想分享一些 Jenkins 自动部署问题的解决方案,我在互联网上找不到,包括这里。
但我几乎是 Whosebug 的新生,所以我只是来问自己并立即回答自己。
// 我试过在GitHub问题上分享解决方案public,我也用不好。
// 请求原谅...
我正在使用 Spring MVC 4.3.9,连接到 CI/CD。
// GitHub 分支 -> Jenkins -> 测试服务器 (Tomcat 8.5)
我允许了所有 IP 地址,在 Jenkins 凭据菜单和 tomcat 中创建并设置了正确的 Tomcat 管理员帐户。
但同样的错误总是发生——TomcatManagerException 和非法参数异常(在 Jenkins 的完整日志中,maven 构建选项,-X -e,不确定)。
// 结果相同,同时使用 Deploy war 插件和 SSH_publish 插件。
这是 Jenkins 控制台输出。 (我不认为这是完整的日志。)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.895 s
[INFO] Finished at: ~~~Time~~~
[INFO] ------------------------------------------------------------------------
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying ~~YourDIR&WAR~~ to container Tomcat 8.x Remote with context ~~YourContextName~~
Redeploying [ ~~YourDIR&WAR~~]
Undeploying ~~YourDIR&WAR~~]
Deploying [ ~~YourDIR&WAR~~]
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [ ~~YourDIR&WAR~~]
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:104)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:180)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
at hudson.FilePath.act(FilePath.java:1075)
at hudson.FilePath.act(FilePath.java:1058)
at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1905)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [~~YourContextName~~] but context failed to start
" instead of the expected "OK" message
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:767)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
... 19 more
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [~~YourContextName~~] but context failed to start
" instead of the expected "OK" message
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:767)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:180)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
at hudson.FilePath.act(FilePath.java:1075)
at hudson.FilePath.act(FilePath.java:1058)
at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1905)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE
* 我在 mapperLocations 设置中的 Maven 控制台中也遇到了非法参数异常。
===> 这是关键
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://yourDBurl:yourport/yourDBname" />
<property name="username" value="youraccountname" />
<property name="password" value="youraccountpassword" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:my/package/mapper/*.xml" />
</bean>
<!--
// This is a part of the root-context.xml
// in `src/main/java/my/package/mapper`, there are XML mapper files. // "src/main/java"
// -- In my case, the mappers were in the classpath `src/main/java`
-->
这是我原来的映射器设置(导致错误)。当我在本地服务器上 运行 Spring 项目时,此设置一切正常。同样在我在 eclipse 上导出 war 文件的情况下,然后用我自己的手手动将 war 部署到服务器。同样在我在 eclipse 上导出 war 文件的情况下,然后将 war 和 Tomcat 管理器手动部署到服务器。
** 但仅在 Jenkins 上不可用。 Maven 构建总是成功的,但只在部署中。 **
* 解决方案 *
=> 我更改了 Spring 项目中的映射器设置,并将映射器从 src/main/java
迁移到 src/main/resources
=> 报错的原因我已经猜到是Jenkins读不到,<property name="mapperLocations" value="classpath:my/package/mapper/*.xml" />
这个配置。
=> 相同的 JDBC 配置,我只是像这样更改了 mybatis 设置。
<!-- with same jdbc config -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/mybatis-configuration.xml" />
</bean>
<!--
// This is a part of the root-context.xml
// NOW in `src/main/resources/my/package/mapper`, there are XML mapper files. // "src/main/resources"
-->
=> 在 src/main/resources/mybatis-configuration.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<!-- <typeAlias alias="yourDTO" type="my.package.dto.yourDTO"></typeAlias> -->
</typeAliases>
<mappers>
<mapper resource="mybatis/mapper/yourmapper.xml" />
<!-- mappers, and so on -->
</mappers>
</configuration>
=> 将 mybatis 映射器放在目录中,src/main/resources/mapper
。像通常的 mybatis mapper XML 文件一样写入 yourmapper.xml
。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="my.package.dto.yourDTO">
<!-- your mybatis tag with SQL query -->
</mapper>
P.S。
-- 我只是猜测 Jenkins 无法读取 src/main/java
中的映射器。
-- 我对Jenkins的开源代码并没有真正的理解和分析。
-- 所以我指出的原因可能是错误的,但至少,在我的神秘案例中,可以使用 Jenkins 进行自动部署。
-- 我希望这可能会有所帮助。
我想分享一些 Jenkins 自动部署问题的解决方案,我在互联网上找不到,包括这里。
但我几乎是 Whosebug 的新生,所以我只是来问自己并立即回答自己。
// 我试过在GitHub问题上分享解决方案public,我也用不好。
// 请求原谅...
我正在使用 Spring MVC 4.3.9,连接到 CI/CD。 // GitHub 分支 -> Jenkins -> 测试服务器 (Tomcat 8.5)
我允许了所有 IP 地址,在 Jenkins 凭据菜单和 tomcat 中创建并设置了正确的 Tomcat 管理员帐户。 但同样的错误总是发生——TomcatManagerException 和非法参数异常(在 Jenkins 的完整日志中,maven 构建选项,-X -e,不确定)。 // 结果相同,同时使用 Deploy war 插件和 SSH_publish 插件。
这是 Jenkins 控制台输出。 (我不认为这是完整的日志。)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.895 s
[INFO] Finished at: ~~~Time~~~
[INFO] ------------------------------------------------------------------------
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying ~~YourDIR&WAR~~ to container Tomcat 8.x Remote with context ~~YourContextName~~
Redeploying [ ~~YourDIR&WAR~~]
Undeploying ~~YourDIR&WAR~~]
Deploying [ ~~YourDIR&WAR~~]
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [ ~~YourDIR&WAR~~]
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:104)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:180)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
at hudson.FilePath.act(FilePath.java:1075)
at hudson.FilePath.act(FilePath.java:1058)
at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1905)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [~~YourContextName~~] but context failed to start
" instead of the expected "OK" message
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:767)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
... 19 more
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [~~YourContextName~~] but context failed to start
" instead of the expected "OK" message
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:767)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:180)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
at hudson.FilePath.act(FilePath.java:1075)
at hudson.FilePath.act(FilePath.java:1058)
at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1905)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE
* 我在 mapperLocations 设置中的 Maven 控制台中也遇到了非法参数异常。
===> 这是关键
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://yourDBurl:yourport/yourDBname" />
<property name="username" value="youraccountname" />
<property name="password" value="youraccountpassword" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:my/package/mapper/*.xml" />
</bean>
<!--
// This is a part of the root-context.xml
// in `src/main/java/my/package/mapper`, there are XML mapper files. // "src/main/java"
// -- In my case, the mappers were in the classpath `src/main/java`
-->
这是我原来的映射器设置(导致错误)。当我在本地服务器上 运行 Spring 项目时,此设置一切正常。同样在我在 eclipse 上导出 war 文件的情况下,然后用我自己的手手动将 war 部署到服务器。同样在我在 eclipse 上导出 war 文件的情况下,然后将 war 和 Tomcat 管理器手动部署到服务器。
** 但仅在 Jenkins 上不可用。 Maven 构建总是成功的,但只在部署中。 **
* 解决方案 *
=> 我更改了 Spring 项目中的映射器设置,并将映射器从 src/main/java
迁移到 src/main/resources
=> 报错的原因我已经猜到是Jenkins读不到,<property name="mapperLocations" value="classpath:my/package/mapper/*.xml" />
这个配置。
=> 相同的 JDBC 配置,我只是像这样更改了 mybatis 设置。
<!-- with same jdbc config -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/mybatis-configuration.xml" />
</bean>
<!--
// This is a part of the root-context.xml
// NOW in `src/main/resources/my/package/mapper`, there are XML mapper files. // "src/main/resources"
-->
=> 在 src/main/resources/mybatis-configuration.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<!-- <typeAlias alias="yourDTO" type="my.package.dto.yourDTO"></typeAlias> -->
</typeAliases>
<mappers>
<mapper resource="mybatis/mapper/yourmapper.xml" />
<!-- mappers, and so on -->
</mappers>
</configuration>
=> 将 mybatis 映射器放在目录中,src/main/resources/mapper
。像通常的 mybatis mapper XML 文件一样写入 yourmapper.xml
。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="my.package.dto.yourDTO">
<!-- your mybatis tag with SQL query -->
</mapper>
P.S。
-- 我只是猜测 Jenkins 无法读取 src/main/java
中的映射器。
-- 我对Jenkins的开源代码并没有真正的理解和分析。
-- 所以我指出的原因可能是错误的,但至少,在我的神秘案例中,可以使用 Jenkins 进行自动部署。
-- 我希望这可能会有所帮助。