java - Maven spring 未解决的符号
问题描述
当尝试在 spring 框架上运行一个简单的应用程序时,我遇到了导入 web 包的问题:
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
我的代码真的很基础,我只是想发回一个简单的 txt
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
AppServerHandler handler = AppServerHandler.getInstance(6666);
}
@RequestMapping(value = "/",method = POST) <--- not familiar with annonation
public String index() {
return AppServerHandler.getWelcomeMsg();
}
}
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我真的很想知道会出什么问题。谢谢。
解决方案
请在您的课程中包含@RestController,如下所示。
@RestController
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
AppServerHandler handler = AppServerHandler.getInstance(6666);
}
@GetMapping(value = "/") <--- use this annotation instead of @Requestmapping
public String index() {
return AppServerHandler.getWelcomeMsg();
}
}
@GetMapping 有 HTTP 方法 GET。
推荐阅读
- discord - Discord.js 音乐机器人加入然后离开
- swift - 如何使用 NSMutableAttributedString、NSMutableParagraphStyle 和 swift 制作带有图片而不是标记的项目符号列表
- css - 选择值后,WooCommerce 产品属性下拉列表可更改文本颜色
- spring-boot - Gradle 子项目不会与子项目的依赖项一起编译
- matplotlib - 有没有办法在这个网格中标记饼图的每个楔形?
- java - Android Studio 中正在进行的呼叫的自定义 UI
- node.js - mongodb 查找 - 依赖于一个字段
- linux - 如何更新我的 gcc,Sudo Apt 更新错误
- spring-boot - Springfox 3.0 切换到旧的显示 URL 回到 swagger-ui.html
- oracle - 密码参数 Oracle 丢失或无效密码