zoukankan      html  css  js  c++  java
  • 使用idea搭建Spring boot开发初始环境

    准备工作

    将以下代码加入idea的live template,命名为springbootStartup

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.3.2.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

    Create New Project


                                                       

     

     

     

     

     

    添加maven支持

    添加pom.xml

    在project的根目录上的右键菜单中选择"Add Framework Support",添加maven支持。


     

     

     

    设置maven坐标


     

    补全maven其他设置

    在pom.xml中,坐标设置下面输入sp,IDE自动弹出前面设置的live template:“springbootStartup”,按下"tab"键盘,剩余的maven代码将会自动补全。


     

     

    新建包结构


     

    新建application类


     

     

     

     

     

    导入:

    import org.springframework.boot.SpringApplication;
    
    

    在main函数中添加如下代码:

    SpringApplication.run(SpringBootDemoApplication.class, args);

    添加controller类


     

    添加@RestController


     

    添加request mapping代码

    @RequestMapping("/hello")
    String hello() {
         return "this is a test";
    }

     

    测试


     

    第一次启动报错,显示8080端口已经被占用



    因此需要修改端口号,操作如下:
    在resources目录下新建application.properties, 输入如下内容:

    server.port=8081

    然后重新启动程序,在浏览器中访问地址:
    http://localhost:8081/hello


     
  • 相关阅读:
    Linux下查看文件内容的命令
    windows下vmware配置nat网络
    xshell连接linux
    django 常见过滤器
    Django模板语言中的自定义方法filter过滤器实现web网页的瀑布流
    关于python开发CRM系统
    关于django form验证是否用户名已存在
    Django model 中的 class Meta 详解
    ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 43. Created with MySQL 5
    并发编程之线程池
  • 原文地址:https://www.cnblogs.com/Milo-CTO/p/7422120.html
Copyright © 2011-2022 走看看