我正在使用Spring启动和REST将旧的Spring / SOAP / Java6程序转换为Java 8,但我无法使其工作。我开始使用简单的控制器等,并添加了招摇,但这也无效。
我的application.yaml
server:
port: 30001
spring:
application:
name: daissywebservice
datasource:
username: USER
password: PW
url: jdbc:oracle:thin:serveraddress
jpa:
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.Oracle10gDialect
show_sql: true
#format_sql: true
data:
rest:
detection-strategy: annotated
#jackson:
#serialization:
#INDENT_OUTPUT: true
management:
endpoints:
cors:
allowed-origins: "*"
# allowed-methods: GET
web:
exposure:
include: info, health, httptrace
的TestController
package com.company.project.webservice.controllers;
@RestController
@RequestMapping("/test")
@Api(value = "test", description = "Actions to test")
public class TestController {
@Autowired
private TestService testService;
@GetMapping("/echo/{in}")
String echo(String in){
return testService.echo(in);
}
}
WebserviceApplication
package com.company.project.webservice;
@SpringBootApplication(
scanBasePackages = {
"com.company.subpackage.location.project1"
})
public class WebserviceApplication {
public static void main(String[] args) {
SpringApplication.run(WebserviceApplication.class, args);
}
}
com.company.subpackage.location.project1
这里是TestService所在的位置,这也是一个较旧的spring和Java项目,但这无关紧要。
的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>com.company.project</groupId>
<artifactId>sproject-module-webservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sproject module webservice</name>
<description>Webservice for project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.company.subpackage.location.project1</groupId>
<artifactId>sproject-module-services</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
致电http://localhost:30001/
给出
{
"_links" : {
"profile" : {
"href" : "http://localhost:30001/profile"
}
}
}
但是当我在控制台中调用http://localhost:30001/swagger-ui.html
时,我看到GET http://localhost:30001/null/swagger-resources/configuration/ui 404 ()
并且有一个像这样的弹出窗口
我想念的是我的所有网络服务都返回404?
答案 0 :(得分:0)
在我看来,如果您尝试在浏览器上显示数据,则应使用spring-boot-starter-web
依赖项而不是spring-boot-starter-rest
。
spring-boot-starter-rest
非常有用。