springBoot01 之HelloWorld
来源:互联网 发布:安卓呼死你软件免费版 编辑:程序博客网 时间:2024/05/01 02:26
1.创建一个maven项目。
2. 在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.4.1.RELEASE</version>
</parent>
3.在dependencies中加入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
4.加入插件,如果我们要直接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>
5.真正的程序开始啦,我们需要一个启动类,然后在启动类申明让spring boot自动给我们配置spring需要的配置,比如:@SpringBootApplication,为了可以尽快让程序跑起来,我们简单写一个通过浏览器访问hello world字样的例子
@SpringBootApplication
@ServletComponentScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class);
}
@RequestMapping("/")
public String index(){
return "hello,world";
}
}
其中@SpringBootApplication申明让spring boot自动给程序进行必要的配置,等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan
@RestController返回json字符串的数据
运行我们的Application了,我们先介绍第一种运行方式。
之后打开浏览器输入地址:http://127.0.0.1:8080/ 就可以看到Hello world!了。
1 0
- springBoot01 之HelloWorld
- SpringBoot01
- SpringBoot01
- SpringBoot01--入门实例
- SpringBoot01 java的配置方式
- SWT 入门之 -> HelloWorld
- drools之helloworld
- RMI 之helloworld(转)
- J2ME入门之HelloWorld
- Struts2之HelloWorld程序
- dwr入门之HelloWorld
- java之HELLOWORLD (applet)
- C#之HelloWorld
- java之HelloWorld
- SpringAOP之HelloWorld
- iText入门之HelloWorld
- DWR之HelloWorld
- aop 之 helloworld
- python请求时cookie处理
- 流程控制语句:分支语句-三元运算符 ?:
- CountDownLatch、CyclicBarrier和Semaphore
- ANdroid NDK学习笔记
- 前端必知必会—HTTP协议
- springBoot01 之HelloWorld
- com.microsoft.sqlserver.jdbc.SQLServerException: 将截断字符串或二进制数据
- 动态增加分组报表组内数据并刷新页面
- java 操作redis (Spring 连接池)
- android 6.0编译时出现ERROR:Security problem ,see jack server log
- VI中的多行删除与复制
- TTTAttributedLabel 使用小记
- Java 时间差运算工具函数(时间戳运算)
- 前端插件