多模块maven项目intellij中的Spring启动配置

时间:2016-08-27 21:15:35

标签: spring maven spring-boot

我在为多模块maven项目正确设置弹簧启动时遇到问题。

我正在尝试创建一个包含两个模块,核心和模块层的多模块项目。核心基于spring boot(tomcat)

父母Pom   - | -----------核心模块(弹簧启动)   - | -----------模块等级

我的问题是如何在maven多模块项目下使用这个tomcat servelt容器配置和运行应用程序。

我的父pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                      http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
    </parent>

  <groupId>parent</groupId>
  <artifactId>parent</artifactId>
    <!--The packaging is defined as ‘pom’ to tell maven not to package-->
  <packaging>pom</packaging>
  <version>1.0</version>
  <name>pfe Soliam Monitoring</name>

    <properties>
        <spring-boot.version>1.3.3.RELEASE</spring-boot.version>
    </properties>

  <modules>
    <module>core</module>
    <module>tierce</module>
  </modules>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.7</source>
            <target>1.7</target>
          </configuration>
        </plugin>
      </plugins>
   </pluginManagement> 
  </build>

  <dependencies>

     <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>compile</scope>
        </dependency>

  </dependencies>
</project>

pom.xml文件核心模块

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>

    <groupId>core</groupId>
    <artifactId>core</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <java.version>1.7</java.version>

            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        </properties>




    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.3.3.RELEASE</version>
            </plugin>
        </plugins>
    </build>
    <dependencies>

        <dependency>
            <groupId>com.thetransactioncompany</groupId>
            <artifactId>cors-filter</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>org.intrace</groupId>
            <artifactId>org.intrace</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>com.oracle</groupId>-->
            <!--<artifactId>ojdbc6</artifactId>-->
            <!--<version>11.2.0.1.0</version>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>

        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jvnet.opendmk</groupId>
            <artifactId>jmxremote_optional</artifactId>
            <version>1.0_01-ea</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.7.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jboss-jmx</artifactId>
            <version>4.2.2.GA</version>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
            <version>5.12.3</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
        </dependency>
        <dependency>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
            <version>2.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.1_spec</artifactId>
            <version>1.0.2.Final</version>
        </dependency>

        <!--<dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jboss-remote-naming</artifactId>
            <version>2.0.4.Final</version>

        </dependency>-->

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher-compiler-2.2</artifactId>
            <version>2.2.5</version>
        </dependency>
    </dependencies>


</project>

tierce pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>tierce</groupId>
    <artifactId>tierce</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <dependencies>

        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-debug-all</artifactId>
            <version>3.3</version>
        </dependency>

        <dependency>
            <groupId>com.goebl</groupId>
            <artifactId>david-webb</artifactId>
            <version>1.3.0</version>
        </dependency>

        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>

基于spring boot(启动tomcat)的运行类

 @SpringBootApplication
    @Component

    public class coreApplication {

        databaseConnectionImpl dbconn = new databaseConnectionImpl();

        public static void main(String[] args) throws Exception {

            SpringApplication.run(coreApplication.class, args);
        }

    }

1 个答案:

答案 0 :(得分:0)

我首先猜测解决方案,但您是否尝试利用核心内的工件层中的功能?如果是这样,您仍然需要在依赖于核心的工件中声明该工件。或者,如果核心是构建大量应用程序的基础,那么您可以将核心包含在您的tierce项目中并从那里启动应用程序。

只是让多个maven模块与类路径上的依赖关系无关。