将具有多个模块的maven项目部署到Tomcat 7.0

时间:2015-11-07 03:50:24

标签: java eclipse maven tomcat

所以我有两个模块,我们称之为moduleA和moduleB。我的目标是将它们都部署到Tomcat。这就是我所做的:

父pom.xml

<project>
  ....
  <artifactId>parentModule</artifactId>
  <packaging>pom</packaging>
  <modules>
    <module>moduleA</module>
    <module>moduleB</module>
  </modules>
  ....
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.4.3</version>
     </dependency>
   </dependencies>
 </dependencyManagement>
 ...
</project>

moduleA pom.xml

<project>
  ...
  <parent>
     ...
     <artifactId>parentModule</artifactId>
  </parent>
  ...
</project>

moduleB pom.xml

<project>
  ...
  <parent>
     ...
     <artifactId>parentModule</artifactId>
  </parent>
  ...
</project>

目录结构如下所示

Users/swidjaja/dev/parentProject
  pom.xml
  moduleA
    pom.xml
  moduleB
    pom.xml

这些是我将其部署到Tomcat的步骤

  1. [在终端上] mvn clean install
  2. [在终端上] mvn eclipse:eclipse
  3. [Eclipse]导入项目
  4. [Eclipse]创建新的Tomcat 7.0服务器并将这两个模块添加到Resources [Eclipse]运行Tomcat服务器
  5. 运行Tomcat服务器,我得到以下异常

    SEVERE: Exception sending context initialized event to listener instance of  class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'awsCredentials' defined in file [/Users/swidjaja/dev/parentProject/moduleA/target/moduleA-SNAPSHOT/WEB-INF/classes/applicationContext.xml]: null
        at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
        at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:220)
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:84)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:656)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    

    这就是applicationContext.xml文件的样子

    <beans>
      <bean id="awsCredentials" class="com.amazonaws.auth.BasicAWSCredentials">
        <constructor-arg index="0" value="accessKey" />
        <constructor-arg index="1" value="secretKey" />
      </bean>
    </beans>
    

    我的猜测是,不知怎的,我没有正确部署它。 BasicAWSCredentials类是aws-java-sdk的一部分,它被定义为父pom.xml中的依赖项,看起来这个模块没有正确部署到Tomcat。

    我的步骤中我做错了什么?部署此类项目的正确方法是什么?我一直在努力奋斗2天。

    非常感谢任何帮助。非常感谢!

0 个答案:

没有答案