三步编写一个spring boot程序

今天学习了下spring boot,查了两篇文章,发现搭建应用确实是快,我用的是eclipse.

第一步,新建一个maven工程,并配置pom.xml.



<!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.0.RC1</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

第二步,新建一个类作为启动应用的类:

@Configuration 
@ComponentScan 
@EnableAutoConfiguration 
public class Application { 
    public static void main(String[] args) { 
        SpringApplication.run(Application.class); 
    } 
}


第三步,新建测试类

@RestController
public class Test {
      @RequestMapping("/")
      public String home() {
        return "hello";
      }   
}

最后执行Application,访问 http://localhost:8080/ ,是不是出来个"hello" ?
文/程忠 浏览次数:0次   2016-09-26 16:48:21

相关阅读

微信扫描-捐赠支持
加入QQ群-技术交流

评论:
点击刷新

↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑