美文网首页
SpringWeb工程创建

SpringWeb工程创建

作者: Quasimodo_403c | 来源:发表于2021-03-24 22:49 被阅读0次

    快速搭建

    1. 创建Java工程
    2. 将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;
    

    相关文章

      网友评论

          本文标题:SpringWeb工程创建

          本文链接:https://www.haomeiwen.com/subject/msjkhltx.html