微服务’ralab-nlp’
- New mocroservice ‘ralab-nlp’ and add the Maven spring-boot-starter-web denpendency
- Add @SpringBootApplication to the application class
- Add HelloController
本文采用maven建立应用程序(服务提供者ralab-nlp),引入spring-web依赖,pom.xml配置如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ralab</groupId>
<artifactId>ralab-nlp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ralab-nlp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
自动生成RalabNlpApplication.java代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16package com.ralab.ralabnlp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
//(scanBasePackages = { "com.ralab.nlp.controller"})
"com.ralab.nlp.controller"}) ({
public class RalabNlpApplication {
public static void main(String[] args) {
SpringApplication.run(RalabNlpApplication.class, args);
}
}
新建HelloController.java1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18package com.ralab.nlp.controller;
//import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
"/nlp") (
public class HelloController {
"/api") (
public String index() {
return "Greetings from Spring Boot!";
}
}
运行RalabNlpApplication