springboot quick start

SpringBootLearning

hello springboot

  • 下载springboot相关的依赖
       
           org.springframework.boot
           spring-boot-starter-parent
           1.5.3.RELEASE
            
       
       
      
           
               org.springframework.boot
               spring-boot-starter-web
           
           
  • 建立一个启动方法(也就是一个普通的main方法)
@SpringBootApplication
public class SpringBootMain {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootMain.class, args);
    }
}

需要注意的是这个main方法必须放在根目录下面,还有在这个项目里不要再有其他的main方法还需要注意必须加上@SpringBootApplication这个注解,这个是springboot启动的注解没它没法玩

  • 创建一个controller
@RestController
public class HelloController {

    /**
     * welcome spring boot
     *
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        return "Greetings from Spring Boot! ";
    }
}

OK了这样springboot就搞定了,是不是很简单,是不是?????

是不是发现spring之前的繁琐配置都没有了,感觉这个时间是不是顿时美好了,but 一个配置也没有是不可能滴,至少我们需要配置端口,我们需要配置数据吧!那好吧我们就来一个配置文件application.properties就是唯一的配置文件啦!我们可以设置端口,数据库,缓存等等。

#端口号
server.port=8888
#切换不同的环境
spring.profiles.active=dev
#spring-jdbc配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root

地址:
地址

源码地址:
http://git.oschina.net/xiaoyuxi/springbootlearning

你可能感兴趣的:(springboot quick start)