码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot的环境搭建

时间:2017-10-20 00:34:23      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:spring boot 入门

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>springstart</groupId>

  

  <artifactId>com.zcp.springstart</artifactId>

  <version>1.0.0</version>

  <packaging>jar</packaging>

  

  <!-- 方式一 :依赖父工程 -->

  <!-- <parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>1.5.8.RELEASE</version>

 </parent> -->

  

  

  <properties>

  <project.bulid.sourceEncoding>UTF-8</project.bulid.sourceEncoding>

  <maven.compiler.source>1.7</maven.compiler.source>

  <maven.compiler.target>1.7</maven.compiler.target>

  </properties>

  

  

  <!-- 方式二: 配置这个依赖 -->

  <dependencyManagement>

  <dependencies>

   <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->

<dependency>

   <groupId>org.springframework.boot</groupId>

   <artifactId>spring-boot-dependencies</artifactId>

   <version>1.5.8.RELEASE</version>

   <type>pom</type>

   <scope>import</scope>

</dependency>

  

  </dependencies>

  </dependencyManagement>

  


  

  

  <dependencies>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter</artifactId>

    </dependency>

</dependencies>

</project>


spring boot的启动入口的方式

package com.zcp.springstart;


import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.context.annotation.Bean;


@SpringBootApplication

public class App {

@Bean

public Runnable createRunnable(){

return new Runnable() {

@Override

public void run() {

System.out.println(">>>>>>>>>>>>runn---------");

}

};

}

public static void main(String[] args) {

ConfigurableApplicationContext context = SpringApplication.run(App.class, args);

context.getBean(Runnable.class).run();

}


}


说明:springboot的启动入口类,默认为配置类,故可以在该类中注入bean。

spring boot的环境搭建

标签:spring boot 入门

原文地址:http://7298246.blog.51cto.com/7288246/1974439

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!