[英]Spring Boot RESTful Web Service
我使用eclipse和spring框架按照本教程Spring Boot RESTful Web服务教程-Java REST API制作简单的Rest服务。 一切都可以在我的台式机上正常工作,但是后来我尝试复制该项目,并在具有相同eclipse版本的笔记本电脑上打开它...
问题是当我启动应用程序时,我无法打开localhost:8080,并且我没有得到“ Whitelabel Error Page”。...只是404。这与我尝试调用rest控制器方法时相同。
当我查看控制台时,在PC上看到以下内容:
但是我在笔记本电脑上的登录略有不同:
我也会在这里发布课程,所以任何人都可以告诉我原因是什么?
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
package com.start.contract.controllers;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.start.contract.datamodel.Contract;
@RestController
@RequestMapping(ContractController.CONTRACT_BASE_URI)
public class ContractController {
public static final String CONTRACT_BASE_URI = "svc/v1/contracts";
@RequestMapping(value = "{contractNumber}")
public Contract getContract(@PathVariable final int contractNumber)
{
Contract contract = new Contract();
contract.setName("Djomla");
contract.setId(contractNumber);
return contract;
}
}
package com.start.contract.datamodel;
public class Contract {
private String name;
private int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Contract [name=").append(name).append(", id=").append(id).append("]");
return builder.toString();
}
}
将此添加到application.properties文件。
server.error.whitelabel.enabled=true
完成手动操作后,对我有用的是更改pom.xml设置,然后将spring boot版本降低为
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
</parent>
代替
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
...现在也可以在我的笔记本电脑上使用...我还是不知道这会是个问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.