我在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类。
@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免费获得。
发布于 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的依赖。
或者您没有正确导入类。
发布于 2017-06-23 07:23:00
您正在访问http://localhost:8080,但是您已经在rest控制器"/hola“中定义了一个映射。因此,您必须访问url http://localhost:8080/hola,因为您的rest控制器中没有任何默认方法。
发布于 2018-02-08 15:46:54
BuildFailure显示你没有在你的类中给出导入语句。以下是缺少的语句
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;包括这些,你就会很好。
https://stackoverflow.com/questions/43828114
复制相似问题