首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Spring Boot的微服务

使用Spring Boot的微服务
EN

Stack Overflow用户
提问于 2017-05-07 13:22:53
回答 3查看 634关注 0票数 0

我在Windows7下工作,我安装了Spring CLI v1.5.3版本。在工作目录中,使用命令

spring init --build maven --groupId com.redhat.examples --版本1.0 --java--版本1.8 --依赖web --name hola--springboot hola--springboot

我创建了holo-springboot应用程序。然后导航到hola-springboot目录,运行$ mvn spring-boot:run

应用程序运行。转到http://localhost:8080,我确实看到了白色标签错误页面。然后,我尝试添加helloworld功能。也就是说,在应用程序的packeage com.example中,我包含了以下java类。

代码语言:javascript
复制
@RestController
@RequestMapping("/api")
public class HolaRestController {
@RequestMapping(method = RequestMethod.GET, value = "/hola",
produces = "text/plain")
public String hola() throws UnknownHostException {
String hostname = null;
try {
hostname = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
hostname = "unknown";
}
return "Hola Spring Boot de " + hostname;
}
}

从hola-springboot目录重新构建,mvn干净包

https://pastebin.com/77Ru0w52中,我遇到构建失败

我搞不懂。有人能帮帮忙吗?我正在阅读Christian Posta撰写的《面向Java开发人员的微服务》一书,第2章,可在Developers Redhat免费获得。

EN

回答 3

Stack Overflow用户

发布于 2017-05-08 06:24:09

看起来你在你的maven pom.xml文件https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/1.5.3.RELEASE中遗漏了对spring boot starter web的依赖。

或者您没有正确导入类。

票数 0
EN

Stack Overflow用户

发布于 2017-06-23 07:23:00

您正在访问http://localhost:8080,但是您已经在rest控制器"/hola“中定义了一个映射。因此,您必须访问url http://localhost:8080/hola,因为您的rest控制器中没有任何默认方法。

票数 0
EN

Stack Overflow用户

发布于 2018-02-08 15:46:54

BuildFailure显示你没有在你的类中给出导入语句。以下是缺少的语句

代码语言:javascript
复制
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.net.InetAddress;
import java.net.UnknownHostException;

包括这些,你就会很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43828114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档