新建spring boot项目时勾选:web和configuration两项
关于注解配置不生效:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
在pom.xml文件配置以上代码
然后用maven reimport 更新下依赖包
Invalidate and restart 重启下
代码:
@RestController @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) public class DemoSApplication { @RequestMapping(value = "/hello") public String getString(){return "Hello World!";} public static void main(String[] args) { SpringApplication.run(DemoSApplication.class, args); } }
运行成功:
访问成功:
修改端口:
在resource目录里的application.properties文件里添加server.port=8088
再次访问: