利用springboot创建一个简单项目
创建简单项目
1.starter 场景启动器:不同的场景启动器维护了所对应的所有的依赖,以简化maven的书写
<parent>
<groupId>org.springframework.boot</groupId>
<version>2.3.5.RELEASE</version>
<artifactId>spring-boot-starter-parent</artifactId>
</parent>
- web包:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
- 打包工具:
部署springboot的插件,只有加了这个插件,当运行 Java -jar xxx.jar才能正常启动
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.4</version>
</plugin>
</plugins>
</build>
- 启动类:
@SpringBootApplication//标记成Springboot 启动类
public class Application {
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}
- properties:
#设置端口
server.port=8282
#项目虚拟目录
server.servlet.context-path=/xuexi
1.使用spring initializer新建一个父maven,type选择POM
2.使用spring initializer 新建一个子maven,type选择maven project
修改子项目中的继承方式:
之前:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
修改后:
<parent>
<groupId>com.xuexi02.springboot</groupId>
<artifactId>spring_boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
-
spring_initializer–>springboot_parent–>spring-boot-starter-parent
-
static:保存所有的静态资源;js,css, images;
-
templates:保存所有的模板页面:(Spring Boot 默认jar包使用嵌入式的Tomcat,默认不支持JSP页面);可以使用模板引擎(free marker、thymeleaf)
-
springboot进行懒加载:
spring.main.lazy-initialization=true
自定义SpringApplication
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication app=new SpringApplication(SpringBootApplication.class);
app.setBannerMode(Banner.Mode.OFF);//可以关闭springboot启动横幅
app.run( args);
}
}