===========================================编写HelloSpringboot========================================
- 编写时pom.xml添加parent,有的公司自己封装一个包用parent供pom.xml继承
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
</parent>
- 而后加入一个依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
2.写一个main方法直接启动springboot
//@SpringBootApplication 这是一个springboot应用
@SpringBootApplication
public class HelloSpringBoot {
public static void main(String[] args) {
SpringApplication.run(HelloSpringBoot.class, args);
}
}
3.写一个controller测试,并且重启springboot
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle01(){
return "Hello,Spring Boot 2!";
}
}
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Apr 25 14:14:48 CST 2021
There was an unexpected error (type=Not Found, status=404).
问题可能是:
- 代码放在启动类同级目录或下级目录中。
- 启动类使用@SpringBootApplication注解。
- controller中缺少@Controller或者@RestController注解。
- 无法访问静态资源。
- 查看配置文件中是否配置context-path,若配置,请求访问的时候就需要加上该路径。
大量简化配置,全部配置集中在application.properties文件中
配置的参数文档
=====================================maven工程打包并且部署=====================================
- 修改package
- 增加build
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
问题:idea 项目的target目录不见了,但是show in explorer可以找到,很不方便。
原因:此文件被忽略了
解决:两种情况
1.设置忽略
2.project视图设置->showExcludeFiles
找到target下的jar包