初识spring boot maven管理--HelloWorld
配置文件配置好 了之后可以进行第一个例子的编写了!
@Controller
@EnableAutoConfiguration()
public class SampleController
{
private Hello hello;
@Autowired
public SampleController(Hello hello)
{
this.hello = hello;
}
@RequestMapping("/")
@ResponseBody
String home(String type)
{
System.out.println("login:" + hello);
return "Hello World";
}
public static void main(String[] args) throws Exception
{
SpringApplication app = new SpringApplication(SampleController.class);
app.setWebEnvironment(true);
app.setShowBanner(false);
Set<Object> set = new HashSet<Object>();
set.add("classpath:applicationContext.xml");
app.setSources(set);
app.run(args);
}
}
右键以java application方式运行,在浏览器上输入:localhost:8080/
显示
说明配置成功了,那么下面对程序简单的分析下:
@Controller 是springMVC使用的注解,标识这个类为控制层类
@EnableAutoConfiguration() springboot使用的注解,必须
@RequestMapping("/") 请求的url地址,缺省为方法名称
@ResponseBody 以json格式返回数据
Set<Object> set = new HashSet<Object>();
set.add("classpath:applicationContext.xml");
自定义spring配置文件的位置,因为springboot使用的是默认的位置,这里可以根据实际情况修改!
初识spring boot maven管理--HelloWorld的更多相关文章
- 初识spring boot maven管理--配置文件
web环境下修改信息需要重启服务器,如果在一个大型的项目中经常重启服务器,那浪费的时间可想而知,今天介绍个好东西 --spring boot!一般学习都是从hello world开始学习的!下面介绍s ...
- 初识spring boot maven管理--属性文件配置
在使用springboot的时候可以使用属性文件配置对属性值进行动态配置,官方文档原文如下: Spring Boot uses a very particular PropertySource ord ...
- 初识spring boot maven管理--使用spring-boot-starter-parent
springboot官方推荐我们使用spring-boot-starter-parent,spring-boot-starter-parent包含了以下信息: 1.使用java6编译级别 2.使用ut ...
- 初识spring boot maven管理--SpringMVC
springboot完美的支持了springmvc,自家东西当然是支持最好的啦! @EnableAutoConfiguration自动注入了一下信息 1.包含了ContentNegotiatingVi ...
- 微服务下 Spring Boot Maven 工程依赖关系管理
单体 Spring Boot Maven 工程 最基本的 pom.xml 包含工程信息.Spring Boot 父工程.属性配置.依赖包.构建插件 <?xml version="1.0 ...
- Spring Boot Maven Plugin(一):repackage目标
简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...
- 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置
在上篇博客初识Spring Boot框架中我们初步见识了SpringBoot的方便之处,很多小伙伴可能也会好奇这个Spring Boot是怎么实现自动配置的,那么今天我就带小伙伴我们自己来实现一个简单 ...
- Spring Boot的Maven插件Spring Boot Maven plugin详解
Spring Boot的Maven插件(Spring Boot Maven plugin)能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Mave ...
- Spring Boot Maven Plugin(二):run目标
简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...
随机推荐
- redis: Zset有序集合类型(七)
存值:zadd myset 1 one 取值:zrange myset 0 -1 127.0.0.1:6379> zadd myset 1 one #存值 分值为1 (integer) 1 12 ...
- Java 理解类加载过程 -- 自定义加载器
类加载器可以看下我的收藏: https://www.cnblogs.com/dongguacai/p/5879931.html 现在准备一个字节码文件: 自定义加载器: package com.xzl ...
- java 容器(collection)--ArrayList 常用方法分析 源码分析
ArrayList 介绍 打开jdk源码看看官方文档的介绍 粗糙的翻译下大致意思是: List接口的可调整大小的数组实现.实现了所有可选的列表操作,并允许所有元素,包括 null .除了实现List接 ...
- jquery选择时分插件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- phpcms 用phpexcel导入导出excel
html <form method="post" action="?m=content&c=content&a=public_add_excel&q ...
- XSS Challenge(1)
XSS Challenges http://xss-quiz.int21h.jp/ Stage #1 注入alert(document.domain),先试一试输入后会返回什么: 返回在标签中,直接尝 ...
- 微软的 Sysinternals 系统管理工具包,例如可找出自动启动的流氓软件
作者:Kenny链接:https://www.zhihu.com/question/52157612/answer/153886419来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- SpringBoot中使用Fastjson/Jackson对JSON序列化格式化输出的若干问题
来源 :https://my.oschina.net/Adven/blog/3036567 使用springboot-web编写rest接口,接口需要返回json数据,目前国内比较常用的fastjso ...
- 华硕笔记本无法U盘启动,快捷键识别不了
http://www.udaxia.com/upqd/8254.html 转载于:https://www.cnblogs.com/wanglinjie/p/10507888.html
- Ubuntu+FastDFS+Nginx
一.安装libfastcommon 1.wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz 2.tar - ...