您的位置:首页 > 编程语言 > Java开发

Spring Boot入门===Hello World

2016-02-22 18:07 399 查看
昨天无意间看到Spring Boot ,今天又了解了一下,试着写一个Hello World! 今天看了半天,最后还是要用Maven最方便!以下:

一、工具

JDK1.7

Eclipse

Maven

这里Eclipse集成Maven的这一步就省了!

二、编码

新建Maven Project 命名为:SpringBoot 选项如图

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
@EnableAutoConfiguration
public 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;

}
}


App.java
修改为8011

======================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: