maven配置springboot
时间: 2023-11-08 07:56:48 浏览: 84
1. 在pom.xml中添加以下依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
```
2. 在application.properties中配置端口和上下文路径:
```
server.port=8080
server.servlet.context-path=/myapp
```
3. 创建一个SpringBoot启动类,添加@SpringBootApplication注解:
```java
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
```
4. 编写Controller类:
```java
@RestController
@RequestMapping("/hello")
public class HelloController {
@GetMapping
public String hello() {
return "Hello, World!";
}
}
```
5. 运行程序,访问http://localhost:8080/myapp/hello,即可看到返回的字符串“Hello, World!”。
阅读全文