maven多模块项目与球衣& amp;弹簧

时间:2015-11-30 07:01:21

标签: java spring jersey maven-3

我一直在提及stackoverflow问题。现在我有了自己的一个。我基本上试图用Jersey 2.22.1创建一个Rest webservice。我正在使用这个原型从1.4节here

创建一个maven jersey项目
   mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp \
                    -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
                    -DgroupId=com.example -DartifactId=simple-service-webapp -Dpackage=com.example \
                    -DarchetypeVersion=2.22.1

这将生成一个样本休息球衣webservice。现在我想通过这个webservice访问mongodb。我正在尝试创建一个单独的jar maven项目,它使用spring连接到mongodb。它的结构是

  • com.yuvi.mongo.service
  • com.yuvi.mongo.dao

我有一个主类内部服务,它加载spring上下文,检索dao bean n执行db访问。

现在我想连接这两个项目。 我创建了一个父项目,将这两个项目作为其模块包含在内,并将mongo添加为服务中的依赖项。但是,当我尝试从我的服务访问包com.yuvi.mongo时,它显示包找不到错误。我创建了两个简单的maven项目,并按照相同的步骤创建了完美运行的多模块项目。但是当我在这里尝试时,我无法访问该包。我在这里显示我的pom文件。

父pom

  <?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>com.yuvi</groupId>
  <artifactId>Parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
    <module>Mongo</module>
    <module>RService</module>
  </modules>
</project>

Mongo pom

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.yuvi</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>com.yuvi.mongo</groupId>
  <artifactId>Mongo</artifactId>
  <name>Mongo</name>
  <url>http://maven.apache.org</url>
  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring-version>4.2.3.RELEASE</spring-version>
        <mongodb-version>1.8.1.RELEASE</mongodb-version>
  </properties>
  <dependencies>

    <!-- Spring 4 dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>${mongodb-version}</version>
        </dependency>


    </dependencies>

</project>

RService pom

<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>com.yuvi</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
    <groupId>com.yuvi.service</groupId>
    <artifactId>RService</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>RService</name>

    <build>
        <finalName>RService</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
           <dependency>
        <groupId>com.yuvi.mongo</groupId>
            <artifactId>Mongo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
       </dependency>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
            <!-- artifactId>jersey-container-servlet</artifactId -->
        </dependency>
        <!-- uncomment this to get JSON support
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>
        -->
    </dependencies>
    <properties>
        <jersey.version>2.22.1</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

0 个答案:

没有答案