springboot的helloworld

来源:互联网 发布:python tts 引擎 编辑:程序博客网 时间:2024/06/14 18:26
//pom.xml//在pom.xml中引入spring-boot-start-parent,spring官方的解释叫什么stater poms,它可以提供dependency management,也就是说依赖管理,引入以后在申明其它dependency的时候就不需要version了,<parent>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-parent</artifactId>    <version>1.5.6.RELEASE</version></parent>开发的是web工程,所以需要在pom.xml中引入spring-boot-starter-web,spring官方解释说spring-boot-start-web包含了spring webmvc和tomcat等web开发的特性。<dependencies>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-web</artifactId>  </dependency></dependencies>如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven 的spring-boot:run的话是不需要此配置的。(我在测试的时候,如果不配置下面的plugin也是直接在Main中运行的。)<build>      <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>               <artifactId>spring-boot-maven-plugin </artifactId>          </plugin>       </plugins></build>

java代码

@SpringBootApplication申明让spring boot自动给程序进行必要的配置,等价于以默认属性使用@Configuration@EnableAutoConfiguration@ComponentScan@RestController返回json字符串的数据,直接可以编写RESTFul的接口;@RestController  @SpringBootApplication  public class App {    @RequestMapping("/")    public String hello(){      return "Hello world!";    }    public static void main(String[] args) {            SpringApplication.run(App.class, args);    }  }  

http://127.0.0.1:8080/ 访问

这里写图片描述

原创粉丝点击