淘先锋技术网

首页 1 2 3 4 5 6 7

记录第一次搭建springcloud项目的各种坑
首先我创建了一个springboot的maven项目,在父类下创建了如下的modules目录这里写图片描述
在eureka-server的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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.cml.springcloud</groupId>
        <artifactId>parent-service</artifactId>
        <version>1.0</version>
    </parent>
    <groupId>com.cml.springcloud</groupId>
    <artifactId>eureka-server</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>eureka-server</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

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

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.19</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/resources</source>
                                <source>src/test/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
                    <version>3.0</version>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <requiresUnpack>
                        <dependency>
                            <groupId>com.sun.jersey</groupId>
                            <artifactId>jersey-server</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>com.sun.jersey</groupId>
                            <artifactId>jersey-core</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>com.sun.jersey</groupId>
                            <artifactId>jersey-servlet</artifactId>
                        </dependency>
                    </requiresUnpack>
                </configuration>

            </plugin>
        </plugins>
    </build>
</project>

当我启动启动服务类时报错如下:
这是我的启动类。
`package com.cml.springcloud;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurakeServerApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(EurakeServerApplication.class).web(true).run(args);
}
}
启动时报错:

Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:)
    ...  common frames omitted

于是我在eureka-server的pom文件中引入了以下依赖

<!-- https://mvnrepository.com/artifact/commons-configuration/commons-configuration -->
<dependency>
    <groupId>commons-configuration</groupId>
    <artifactId>commons-configuration</artifactId>
    <version>1.10</version>
</dependency>

项目启动成功!