当前位置:首页 > 编程世界 2017年11月27日
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。