简体   繁体   English

当所有设置都正确时,Jenkins 自动部署失败。 — mapperLocations 中的错误,Spring (illegalArgumentException, TomcatManagerException)

[英]Jenkins auto deploying failed, when all settings are right. — error in mapperLocations, Spring (illegalArgumentException, TomcatManagerException)

I want to share some Jenkins auto-deployment issue solutions, that I could not find on the internet including here.我想分享一些 Jenkins 自动部署问题解决方案,我在互联网上找不到,包括这里。
But I'm almost a freshman in StackOverflow, so I'm just here to ask myself and answer myself right away.但我几乎是 StackOverflow 的新生,所以我只是在这里问自己并立即回答自己。
// I have tried to share the solution public on GitHub issue, I could not use it well, too. // 我已经尝试在GitHub问题上分享解决方案,我也不能很好地使用它。
// asking to be excused... // 请求原谅...


I'm using Spring MVC 4.3.9, connected to CI/CD. 我正在使用 Spring MVC 4.3.9,连接到 CI/CD。 // GitHub branch -> Jenkins -> TestServer (Tomcat 8.5) // GitHub 分支 -> Jenkins -> TestServer (Tomcat 8.5)

I allowed all the IP addresses, made and set the right Tomcat Manager account both in Jenkins credentials menu and tomcat.我允许所有 IP 地址,在 Jenkins 凭据菜单和 Z1B359D875387AAEDZBEFFAD875387AAB355 中创建并设置正确的 Tomcat 经理帐户。 But the same error always occurs -- TomcatManagerException and also the illegal argument exception (in the full log from Jenkins by maven build option, -X -e, not sure).但是总是会发生同样的错误——TomcatManagerException 以及非法参数异常(在 maven 构建选项的 Jenkins 的完整日志中,-X -e,不确定)。 // Same results, with both Deploy war plugin and SSH_publish plugin. // 结果相同,同时使用 Deploy war 插件和 SSH_publish 插件。

Here is the Jenkins console output.这是 Jenkins 控制台 output。 (I don't think this one is the full log.) (我认为这不是完整的日志。)

 [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$3.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$3.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


* I also got illegal argument exception in maven console, in mapperLocations setting. * 我还在 maven 控制台的 mapperLocations 设置中遇到非法参数异常。
===> This is the key ===> 这是关键

    <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`
-->

This was my original mapper setting (causing the error).这是我原来的映射器设置(导致错误)。 This setting just worked all fine when I run the Spring project on the local server.当我在本地服务器上运行 Spring 项目时,此设置运行良好。 Also in the case that I exported war file on eclipse then deploy the war with my own hand to the server manually.同样在我在 eclipse 上导出战争文件的情况下,然后手动将战争部署到服务器。 Also in the case that I exported war file on eclipse then deploy the war with Tomcat Manager to the server manually.同样在我在 eclipse 上导出战争文件的情况下,然后使用 Tomcat 管理器手动将战争部署到服务器。
** But only not available on Jenkins. ** 但仅在 Jenkins 上不可用。 Maven build was always successful but only in deployment. Maven 构建始终成功,但仅在部署中。 ** **

* Solution * => I have changed the mapper setting in the Spring project, and migrated mappers from src/main/java to src/main/resources => The cause of the error I have guessed is that Jenkins cannot read, <property name="mapperLocations" value="classpath:my/package/mapper/*.xml" /> , this configuration. * 解决方法 * => 我在Spring项目中更改了mapper设置,将mapper从src/main/java迁移到src/main/resources => 错误原因我猜到是Jenkins无法读取, <property name="mapperLocations" value="classpath:my/package/mapper/*.xml" /> ,这个配置。 => Same JDBC config, I only changed the mybatis setting like this. => 相同的 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"
-->


=> In src/main/resources/mybatis-configuration.xml => 在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>


=> Put the mybatis mappers in the directory, src/main/resources/mapper . => 将 mybatis 映射器放在目录src/main/resources/mapper中。 Write yourmapper.xml like usual mybatis mapper XML file.像通常的 mybatis 映射器 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>


PS -- I just have guessed that Jenkins cannot read the mappers in src/main/java . PS - 我只是猜测 Jenkins 无法读取src/main/java中的映射器。 -- I haven't actually understood or analyze the open-source code of Jenkins. -- Jenkins的开源代码我还没有真正理解或分析过。 -- So the cause I pointed out might be wrong, but at least, the auto-deployment with Jenkins was available, in my mysterious case. - 所以我指出的原因可能是错误的,但至少,在我的神秘案例中,Jenkins 的自动部署是可用的。 -- I hope this might be helpful. - 我希望这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM