• 解决 maven构建的web项目无法在外部Tomcat中运行的问题


    今天遇到 maven构建的web项目在idea中能正常运行但打成war包后在外部容器tomcat中无法运行的问题。总结一下遇到的问题:
    第一个问题:项目结构不对
    我的项目结构:

    一般maven项目是:
    明显少了一层 java maven在打包时会以src/main/java 作为package的sources root 但我的项目中没有这个目录就会导致 在spring的配置文件中配置的包路径 全都不正确;贴一个报错信息
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'job' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'IapIosTaskSer' while setting bean property 'targetObject';
    所以后来在项目中添加了java这个文件夹,然后把原来的com文件夹移动到java下面;
    题外说一句:我用的IDE是idea那么我在idea中是如何把项目跑起来的了。
    idea是可以指定sources root 的,指定后的就可以根据路径找到类了。
    第二个问题:mapper.xml没打包
    打成war后mapper.xml全都不见了,所以在调用mapper层方法的时候,都要报错。解决办法在网上找了个办法;在pom.xml中添加了这段代码。
    <build>
      <resources>
        <resource>
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.xml </include>
          </includes>
        </resource>
        <resource>
          <directory>src/main/resources</directory>
          <includes>
            <include>**/*.* </include>
          </includes>
        </resource>
    
        <resource>
          <directory>src/main/webapp/WEB-INF</directory>
          <includes>
            <include>*.xml </include>
            <include>*.properties </include>
          </includes>
        </resource>
      </resources>
    </build>
    

      

    解决这2个问题后就顺利的在外部的tomcat中运行起来了
  • 相关阅读:
    JavaScript学习总结(八)——JavaScript数组
    oracle数据库优化学习笔记
    把连续日期组织起来的算法
    转:andriod的盈利模式分析
    ASP.NET 页生命周期
    .NET垃圾回收机制[引用]
    IIS 7.0 的 ASP.NET 应用程序生命周期
    table滑动选择行及从表记录对应js代码
    hdu 3594 Cactus
    Java 计算器
  • 原文地址:https://www.cnblogs.com/lxoy/p/7412611.html
Copyright © 2020-2023  润新知