springboot程序员

springboot quick start

2017-08-27  本文已影响14人  小鱼嘻嘻

SpringBootLearning

hello springboot

       <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>1.5.3.RELEASE</version>
           <relativePath/> <!-- lookup parent from repository -->
       </parent>
       <!--web应用需要的依赖 -->
      <dependencies>
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
           </dependency>
       <dependencies>    
@SpringBootApplication
public class SpringBootMain {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootMain.class, args);
    }
}

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

@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

上一篇 下一篇

猜你喜欢

热点阅读