初识spring boot maven管理--HelloWorld(一)

2014-11-23 23:19:23 · 作者: · 浏览: 2

配置文件配置好 了之后可以进行第一个例子的编写了!

@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 set = new HashSet();
set.add("classpath:applicationContext.xml");
app.setSources(set);
app.run(args);
}
}

右键以java application方式运行,在浏览器上输入:localhost:8080/

显示\

说明配置成功了,那么下面对程序简单的分析下:< http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+QENvbnRyb2xsZXIgysdzcHJpbmdNVkPKudPDtcTXor3io6yx6sq21eK49sDgzqq/2NbGsuPA4Dxicj4KQEVuYWJsZUF1dG9Db25maWd1cmF0aW9uKCkgc3ByaW5nYm9vdMq508O1xNeiveKjrLHY0Os8YnI+CjwvcD4KPHA+QFJlcXVlc3RNYXBwaW5nKA=="/") 请求的url地址,缺省为方法名称
@ResponseBody 以json格式返回数据

Set set = new HashSet();
set.add("classpath:applicationContext.xml");

自定义spring配置文件的位置,因为springboot使用的是默认的位置,这里可以根据实际情况修改!








<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
分享到: 更多
<script type="text/java script" id="bdshare_js" data="type=tools&uid=12732"> <script type="text/java script" id="bdshell_js"> <script type="text/java script"> var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}}; document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000)
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力
上一篇: java核心知识点学习----equals和==的比较、单例模式
下一篇: 最后一页
相关文章
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<iframe src="http://www.2cto.com/uapi.php tid=293283&catid=85&title=s/XKtnNwcmluZyBib290IG1hdmVuudzA7S0tSGVsbG9Xb3JsZA==&forward=http://www.2cto.com/kf/201404/293283.html" width="100%" height="100%" id="comment_iframe" name="comment_iframe" frameborder="0" scrolling="no">
<script type="text/java script">BAIDU_CLB_fillSlot("771057");
排行
热门
<script type="text/java script">BAIDU_CLB_fillSlot("406189");
<script type="text/java script">BAIDU_CLB_fillSlot("703749");
<iframe frameborder="0" name="Iframe1" src="http://www.2cto.com/bbsdy/index.html" width="100%" height="200"> 您的浏览器不支持嵌入式框架,或者当前配置为不显示嵌入式框架。
<script type="text/java script">BAIDU_CLB_fillSlot("182692");
文章
下载
读书
<script type="text/java script">BAIDU_CLB_fillSlot("771043");
<script type="text/java script"> <script language="java script" src="http://www.2cto.com/api.php op=count&id=293283&modelid=1"> <script type="text/ja