初识SpringBoot(1)

2017-07-17  本文已影响0人  RalapHao
//parent节点作用:引入自动选择version功能,之后所有的jar都不用配置version
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
  </parent>

  <properties>
    <java.version>1.7</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

@RestController
public class BootController {
    @RequestMapping("/hel")
    public String hel() {
        return "I am first boot";
    }
}

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

` 注意

  1. 启动时报错

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

原因:启动类不能直接放到java/main下面,需要自己创建包放入

  1. 访问localhost:8080/hel 出现404
    可能原因:路径不正确,App启动类要放到所有类的同级包含所有类的包下;
上一篇下一篇

猜你喜欢

热点阅读