一个完整的springboot native demo
时间: 2023-07-01 17:10:36 浏览: 99
springboot的demo
以下是一个完整的 Spring Boot Native Demo 的代码:
```java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class NativeDemoApplication {
public static void main(String[] args) {
SpringApplication.run(NativeDemoApplication.class, args);
}
}
```
```java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@Value("${message}")
private String message;
@GetMapping("/")
public String hello() {
return message;
}
}
```
在 resources 目录下添加 application.properties 文件,并添加以下内容:
```
message=Hello World!
```
使用 Maven 构建打包:
```shell
mvn clean package -DskipTests -Pnative
```
运行生成的可执行文件:
```shell
./target/native-demo
```
访问 http://localhost:8080/ ,即可看到页面显示 Hello World!
阅读全文