Idea intellij jdk 1.7通过maven创建Springboot项目

1.这里将介绍比较原始的方法。idea 2017.1,当你的jdk是1.8是很好创建springboot项目的,只要通过idea 的spring initial即可方便的创建,这里我的是1.7,因此还没找到怎么通过该方法创建springboot项目。

jdk1.7创建Springboot项目,这里你需要先配置在Idea 上配置maven,如下所示。

 下面创建一个module,类似在eclipse下的工作空间创建一个project。而idea上的project 类似eclipse上的工作空间

 得到的结果如下所示

 引入springboot依赖,如果你是新建module,在这个module的父包project中引入了,则该module中的pom.xml不用引入如下的依赖。

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>//注意设定java版本
    </properties>
    <!-- Add typical dependencies for a web application -->
    <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>1.4.7.RELEASE</version>//注意这里我的jdk版本时1.7因此需要对应springboot的版本,其实这里也可以用别的版本例如1.5.9,但是不能用1.5.19和最新版的2以上的版本(自己测试的就这么多)
        <relativePath/>
    </parent>

在该module下新建controller和application类

对应代码为HelloApplication

package app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
 * hello Created by pingf
 *
 * @Date 2019/1/10 - 10:55 .
 */
@SpringBootApplication
@ComponentScan(value = "controller")
public class HelloApplication {
    public static void main(String[] args){
        SpringApplication.run(HelloApplication.class,args);
    }

}

 HelloController代码

package controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * hello Created by pingf
 *
 * @Date 2019/1/10 - 10:52 .
 */
@RestController
@EnableAutoConfiguration
public class Hellocontroller {
    @RequestMapping("/hello")
    public String hello(){
        return "hello world idea";
    }
}

启动项目即可。最后的 结果为

猜你喜欢

转载自blog.csdn.net/weixin_39912556/article/details/86223160
今日推荐