zoukankan      html  css  js  c++  java
  • springBoot的三种启动方式

    最近刚学springboot 算是自己的学习笔记  愿自己的努力都会有回报吧 

    第一种方法 

       使用注解@EnableAutoConfiguration注解

    @RestController //表示返回值为json
    @EnableAutoConfiguration//自动配置
    public class HelloController {
        @RequestMapping("/hello")
        public String index() {
            return "Hello World";
        }    
    public static void main(String[] args) {
            SpringApplication.run(HelloController.class, args);
        }
    }

    启动主程序,打开浏览器访问http://localhost:8080/index,可以看到页面输出Hello World

    第二种方式  

    1 单独写一个类 作为程序的入口 在此类中写主方法

    @ComponentScan(basePackages = "com.feng.controller")
    @EnableAutoConfiguration
    public class App {
        public static void main(String[] args) {
            SpringApplication.run(App.class, args);
        }
    }

    @componentScan是控制扫包的范围  这个在类似传统项目的配置文件中的扫包

    第三种方式

    第三种方式也是开发中用到的 在第二种的基础上改变而来的

    用 @SpringBootApplication注解代替@ComponentScan(),@EnableAutoConfiguration 这两个注解  要注意 @SpringBootApplication的扫包范围是当前类的包 和其同级包(包括子包)

  • 相关阅读:
    python处理excel文件
    Python datetime模块
    OrderedDict 有序字典以及读取json串时如何保持原有顺序
    ansible 学习笔记
    nginx的location和rewrite
    实体机重装系统
    热词
    教育
    生活
    1、两数之和
  • 原文地址:https://www.cnblogs.com/guoyafenghome/p/9348641.html
Copyright © 2011-2022 走看看