便捷的springboot框架

第一章 初识springBoot

      最近工作不是很忙!可以闲下来写点东西了。先说优点吧!

     1: Spring Boot使编码变简单

     2: Spring Boot使配置变简单

     3: Spring Boot使部署变简单

     4: Spring Boot使监控变简单

     具体好与坏!等我们掀起她的盖头之后再做评价吧。。

    springboot由于自身嵌入tomcat-embed-el等原因使其可以不用依赖于外部的tomcat去单独启动服务。


    以下是简单示例实现RESTAPI访问

    步骤一


         官网下载相应jar: http://projects.spring.io/spring-boot/      目前本人使用版本为1.5.4.RELEASE

 步骤二

   直接上图吧

 

  具体代码如下

  1:testController.java

 

package controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/springboot")
public class testController {

    @RequestMapping(value = "/rest")
	public String getData() {
		return "恭喜恭喜!   你已初步使用springboot的RestAPI访问!";
	}
}

 2:start.java

package applicationStart;

import java.net.UnknownHostException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;


@Configuration  
@ComponentScan(basePackages = "controller")
@SpringBootApplication
public class Start {
    public static void main(String[] args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(Start.class);
        ConfigurableApplicationContext ConfigurableApplicationContext= app.run(args);
       String beanNames[]=ConfigurableApplicationContext.getBeanFactory().getBeanNamesForAnnotation(RestController.class);
        System.out.println("所以beanNames个数:"+beanNames.length);
        for(String bn:beanNames){
            System.out.println(bn);
        }
      
    }
}


 

 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值