SpringWeb工程创建
2021-03-24 本文已影响0人
Quasimodo_403c
快速搭建
- 创建Java工程
-
将Java工程转换为Maven架构
image.png
3.快速引入依赖
ctrl + insert
<groupId>com.mylx</groupId>
<artifactId>springbootwo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
</parent>
4.创建启动类
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.mylx.springboottwo")
@Configuration
public class ApplicationStart {
public static void main(String[] args) {
SpringApplication.run(ApplicationStart.class,args);
}
}
//或者用已下注解,但要将启动类放置在想要搜索的目录中
/*
@SpringBootApplication
public class ApplicationStart {
public static void main(String[] args) {
SpringApplication.run(ApplicationStart.class,args);
}
}
*/
5.编写controller
@RestController
public class testController {
@GetMapping("/")
public String test(){
return "test";
}
}
6.打包发布
添加插件,点击package
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
7.编写bat运行
@echo off
set JAVA_HOME=H:\Program Files\Java\jdk1.8.0_45
set CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOMe%\lib\tools.jar;
set Path=%JAVA_HOME%\bin;
java -jar D:/li-spring/springbootwo/target/springbootwo-1.0-SNAPSHOT.jar
pause;