/ env上的spring配置错误

时间:2017-04-12 15:35:05

标签: spring-boot spring-cloud spring-cloud-config

我正在尝试使用spring cloud配置,对于1.3.0.release版本,我成功启动了服务器

curl localhost:8888/foo/development returns

{"name":"foo","profiles":["development"],"label":null,"version":null,"state":null,"propertySources":[{"name":"https://github.com/spring-cloud-samples/config-repo/foo-development.properties","source":{"bar":"spam","foo":"from foo development"}},{"name":"https://github.com/spring-cloud-samples/config-repo/foo.properties","source":{"democonfigclient.message":"hello spring io","foo":"from foo props"}},{"name":"https://github.com/spring-cloud-samples/config-repo/application.yml","source":{"info.description":"Spring Cloud Samples","info.url":"https://github.com/spring-cloud-samples","eureka.client.serviceUrl.defaultZone":"http://localhost:8761/eureka/","foo":"baz"}}]}

我尝试使用下面的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>org.springframework</groupId>
    <artifactId>gs-spring-config</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>Brixton.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!-- tag::tests[] -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- end::tests[] -->
    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

然后我使用mvn spring-boot:run,它总是停止

如果我添加依赖

                org.springframework.boot                 弹簧引导启动的Web             

它可以启动,但是当我访问localhost:8080 / env时,它总是返回404,这里缺少什么?

Hello.java

    package hello;

    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.bind.annotation.RequestMapping;

    @RestController
    public class HelloController {

        @RequestMapping("/")
        public String index() {
            return "Hello World";
        }

    }

1 个答案:

答案 0 :(得分:1)

如评论中所述,包括:

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