Spring Boot入门===Hello World
来源:互联网 发布:淘宝拍衣服多少钱一套 编辑:程序博客网 时间:2024/05/08 21:13
http://www.cnblogs.com/liangblog/p/5207855.html
昨天无意间看到Spring Boot ,今天又了解了一下,试着写一个Hello World! 今天看了半天,最后还是要用Maven最方便!以下:
一、工具
JDK1.7
Eclipse
Maven
这里Eclipse集成Maven的这一步就省了!
二、编码
新建Maven Project 命名为:SpringBoot 选项如图
2、修改工程目录,添加源文件夹后目录如下:
3、修改pom.xml文件如下:
4、编辑JAVA代码新建APP.class
运行此代码 服务端口默认8080 访问localhost:8080/h 展示Hello
localhost:8080/w 展示World
OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
---------------风格线---------------------
新建RestController风格的Controller
新建UserController
需修改App.java
运行App.java 访问 http://localhost:8080/user/12
新建其他Controller
重启程序 访问http://localhost:8080/file/name
======================================================
修改默认端口
一、
package com.lgp.SpringBoot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@SpringBootApplicationpublic class MainApplication implements EmbeddedServletContainerCustomizer{ @Override public void customize(ConfigurableEmbeddedServletContainer container) { container.setPort(8011); } public static void main(String[] args) {// SpringApplication.run(MainApplication.class, args); SpringApplication.run(FileController.class, args); } @RequestMapping("/main") public String testPort(){ return "Hello 端口8011......"; }}
二、
package com.lgp.SpringBoot;import java.util.concurrent.TimeUnit;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@EnableAutoConfigurationpublic class App { @RequestMapping("/h") public String home() { return "Hello"; } @RequestMapping("/w") public String word() { return "World"; } public static void main( String[] args ) { System.out.println( "Hello World ! App!" ); //SpringApplication.run(App.class, args); SpringApplication.run(UserController.class, args); } @Bean public EmbeddedServletContainerFactory servletFactory(){ TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory(); tomcatFactory.setPort(8011); tomcatFactory.setSessionTimeout(10,TimeUnit.SECONDS); return tomcatFactory; }}
修改为8011
======================================================
- Spring Boot入门===Hello World
- Spring Boot入门===Hello World
- Spring Boot快速入门之Hello World
- (2) spring boot 入门Hello World
- spring boot 入门篇Hello world
- Spring Boot快速入门(Hello World)
- Spring boot 入门第一天Hello world
- spring-boot-hello-world
- spring-boot Hello World
- hello World Spring Boot
- spring boot入门之环境安装以及Hello World
- spring boot 入门(一):IntelliJ IDEA 实现hello world
- Spring Boot学习入门篇(一)--Hello World
- Spring入门hello world
- spring boot 之 hello world !
- Spring Boot:简单Hello World
- Spring Boot 的 Hello World
- Spring Boot 之Hello World
- 【VK Cup 2016 - Round 1 (Div 2 Edition)C Bear and Forgotten Tree 3 (构造)
- 轮播
- Disks--计算几何
- Lynx使用指南
- Eclipse 远程调试 WebSphere Application Server (WAS)
- Spring Boot入门===Hello World
- jquery eval解析JSON中的注意点介绍
- 在java的Map集合中,怎样更改value的值
- JAR文件揭密
- proftpd限制匿名用户的配置
- web form excel导入
- JAVA中jar文件的编写和应用
- 我们是怎样的一代人? -- 八零后
- 选择排序