SpringBoot的helloword项目

1.pom添加依赖以及配置

 <parent>
    <artifactId>spring-boot-starter-parent</artifactId>
    <groupId>org.springframework.boot</groupId>
    <version>2.2.2.RELEASE</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

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

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

2.设置controller类

@RestController
public class helloController {
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello spring-boot";
    }
}

3.设置启动类

@SpringBootApplication
//对相应的包进行扫描
@ComponentScan(basePackages = {"org.example.springboot.controller"})
public class starter {
    public static void main(String[] args) {
        SpringApplication.run(starter.class);
    }
}

4.自定义banner(在resource中设置banner.txt,项目启动时自动读取)

@SpringBootApplication
//对相应的包进行扫描
@ComponentScan(basePackages = {"org.example.springboot.controller"})
public class starter {
    public static void main(String[] args) {
        SpringApplication.run(starter.class);
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-15 17:32
点赞 评论 收藏
分享
07-15 11:41
门头沟学院 Java
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:16
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务