{"id":2787,"date":"2018-05-13T19:11:21","date_gmt":"2018-05-13T11:11:21","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2787"},"modified":"2018-05-13T19:12:49","modified_gmt":"2018-05-13T11:12:49","slug":"springbootapplication-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2787","title":{"rendered":"@SpringBootApplication \u6ce8\u89e3\u6559\u7a0b"},"content":{"rendered":"<p>\n\tSpring Boot \u73b0\u5728\u5f88\u706b\u554a\uff0c\u706b\u5230\u4f60\u4e0d\u5b66\u4e60\uff0c\u53ef\u80fd\u51e0\u5e74\u540e\u4f60\u5c31\u88ab\u6dd8\u6c70\u4e86\u3002\u73b0\u5728\u5927\u7684\u516c\u53f8\uff0c\u5305\u62ec\u4e00\u4e9b\u652f\u4ed8\uff0c\u7535\u5546\u7b49\u5c0f\u516c\u53f8\u90fd\u5728\u4f7f\u7528 Spring Boot\u3002\u6240\u4ee5\u6211\u4eec\u8fd8\u662f\u5f88\u6709\u5fc5\u8981\u5bf9\u5b83\u8fdb\u884c\u4e00\u4e0b\u7cfb\u7edf\u7684\u5b66\u4e60\u3002\u672c\u6587\u5c06\u4ecb\u7ecd @SpringBootApplication \u6ce8\u89e3\u7684\u4f5c\u7528\u4ee5\u53ca SpringBoot \u662f\u5982\u4f55\u8fd0\u884c\u7684\u3002\n<\/p>\n<p>\n\t@SpringBootApplication \u6ce8\u89e3\u662f\u7528\u6765\u6765\u6807\u6ce8\u4e00\u4e2a\u7c7b\uff0c\u8bf4\u660e\u8fd9\u662f\u4e00\u4e2aSpring Boot\u5e94\u7c7b\u3002\n<\/p>\n<p>\n\t@SpringBootApplication \u6ce8\u89e3\u6807\u8bb0\u7684\u7c7b\uff0c\u5e76\u4e0d\u4e00\u5b9a\u9700\u8981\u5305\u542b main \u65b9\u6cd5\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\npublic class XttblogApplication {\r\n    public static void main(String[] args) {\r\n\t\t\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\n        \/\/ Spring\u5e94\u7528\u542f\u52a8\u8d77\u6765\r\n\t\t\/\/ HelloWorldMainApplication \u7c7b\u662f@SpringBootApplication\u6807\u8bb0\u7684\u7c7b\u3002\r\n        SpringApplication.run(HelloWorldMainApplication.class,args);\r\n    }\r\n}<\/pre>\n<p>\n\t@SpringBootApplication \u6ce8\u89e3\u7684&nbsp;HelloWorldMainApplication.class \u7c7b\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n@SpringBootApplication\r\npublic class HelloWorldMainApplication {\r\n}<\/pre>\n<p>\n\t\u4e5f\u5c31\u662f\u8bf4&nbsp;@SpringBootApplication \u6ce8\u89e3\u53ef\u4ee5\u548c main \u65b9\u6cd5\uff0c\u4e5f\u5c31\u662f&nbsp;SpringApplication.run() \u65b9\u6cd5\u5206\u5f00\u3002\u5e76\u4e0d\u4e00\u5b9a\u975e\u8981\u5728\u4e00\u4e2a\u7c7b\u4e2d\u3002\n<\/p>\n<p>\n\t@SpringBootApplication\uff1aSpring Boot\u5e94\u7528\u6807\u6ce8\u5728\u67d0\u4e2a\u7c7b\u4e0a\u8bf4\u660e\u8fd9\u4e2a\u7c7b\u662fSpringBoot\u7684\u4e3b\u914d\u7f6e\u7c7b\uff0cSpringBoot\u5c31\u5e94\u8be5\u8fd0\u884c\u8fd9\u4e2a\u7c7b\u7684main\u65b9\u6cd5\u6765\u542f\u52a8SpringBoot\u5e94\u7528\u3002\n<\/p>\n<p>\n\t@SpringBootApplication \u662f\u4e00\u4e2a\u7ec4\u5408\u6ce8\u89e3\uff0c\u4e3b\u8981\u5305\u542b @SpringBootConfiguration \u548c @EnableAutoConfiguration \u8fd9\u4e24\u4e2a\u6ce8\u89e3\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n@Target(ElementType.TYPE)\r\n@Retention(RetentionPolicy.RUNTIME)\r\n@Documented\r\n@Inherited\r\n@SpringBootConfiguration\r\n@EnableAutoConfiguration\r\n@ComponentScan(excludeFilters = {\r\n      @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),\r\n      @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })\r\npublic @interface SpringBootApplication {<\/pre>\n<ul>\n<li>\n\t\t@SpringBootConfiguration\uff1aSpring Boot\u7684\u914d\u7f6e\u7c7b\uff1b\u6807\u6ce8\u5728\u67d0\u4e2a\u7c7b\u4e0a\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2aSpring Boot\u7684\u914d\u7f6e\u7c7b\uff1b@Configuration\uff1a\u914d\u7f6e\u7c7b\u4e0a\u6765\u6807\u6ce8\u8fd9\u4e2a\u6ce8\u89e3\uff1b\u914d\u7f6e\u7c7b &#8212;&#8211; &nbsp;\u914d\u7f6e\u6587\u4ef6\uff1b\u914d\u7f6e\u7c7b\u4e5f\u662f\u5bb9\u5668\u4e2d\u7684\u4e00\u4e2a\u7ec4\u4ef6\uff1b@Component\n\t<\/li>\n<li>\n\t\t@EnableAutoConfiguration\uff1a\u8fd9\u662f\u4e00\u4e2a Spring Boot \u7684\u4e00\u4e2a\u6838\u5fc3\u6ce8\u89e3\u7c7b\u3002\u4ed6\u662f Spring Boot \u4e0d\u9700\u8981\u914d\u7f6e\uff0c\u6216\u8005\u505a\u5230\u96f6\u914d\u7f6e\u7684\u4e00\u4e2a\u5173\u952e\u6ce8\u89e3\u3002\u5b83\u4e3b\u8981\u7684\u4f5c\u7528\u662f\u5f00\u542f\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\uff1b\u4ee5\u524d\u6211\u4eec\u9700\u8981\u914d\u7f6e\u7684\u4e1c\u897f\uff0cSpring Boot\u5e2e\u6211\u4eec\u81ea\u52a8\u914d\u7f6e\uff1b@EnableAutoConfiguration \u544a\u8bc9 SpringBoot \u5f00\u542f\u81ea\u52a8\u914d\u7f6e\u529f\u80fd\uff1b\u8fd9\u6837\u81ea\u52a8\u914d\u7f6e\u624d\u80fd\u751f\u6548\uff1b\u5173\u4e8e&nbsp;@EnableAutoConfiguration \u6ce8\u89e3\uff0c\u6211\u4eec\u5c06\u5355\u72ec\u6765\u505a\u4e00\u7ae0\u8fdb\u884c\u5b66\u4e60\u3002\u56e0\u4e3a\u5b83\u662f\u6574\u4e2a Spring Boot \u7684\u4e00\u4e2a\u6838\u5fc3\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t@SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan\u3002\n<\/p>\n<p>\n\t@Configuration\uff1a\u63d0\u5230@Configuration\u5c31\u8981\u63d0\u5230\u4ed6\u7684\u642d\u6863@Bean\u3002\u4f7f\u7528\u8fd9\u4e24\u4e2a\u6ce8\u89e3\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684spring\u914d\u7f6e\u7c7b\uff0c\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3\u76f8\u5e94\u7684xml\u914d\u7f6e\u6587\u4ef6\u3002\n<\/p>\n<p>\n\t\u5177\u4f53\u53ef\u4ee5\u770b\u4e0b\u9762\u7684\u793a\u4f8b\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n&lt;beans&gt;  \r\n    &lt;bean id = &quot;xttblog&quot; class=&quot;com.test.Xttblog&quot;&gt;  \r\n        &lt;property name=&quot;url&quot; ref = &quot;test&quot;&gt;&lt;\/property&gt;  \r\n    &lt;\/bean&gt;  \r\n    &lt;bean id = &quot;wheel&quot; class=&quot;com.test.Test&quot;&gt;&lt;\/bean&gt;  \r\n&lt;\/beans&gt; <\/pre>\n<p>\n\t\u800c\u4f7f\u7528\u4e86 @Configuration&nbsp;\u6211\u4eec\u5c31\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\n@Configuration  \r\npublic class Conf {  \r\n    @Bean  \r\n    public Xttblog getXttblog() {  \r\n        Xttblog a = new Xttblog();  \r\n        a.setUrl(getTest());  \r\n        return a;  \r\n    }  \r\n    @Bean   \r\n    public Test getTest() {  \r\n        return new Test();  \r\n    }  \r\n} <\/pre>\n<p>\n\t@Configuration\u7684\u6ce8\u89e3\u7c7b\u6807\u8bc6\u8fd9\u4e2a\u7c7b\u53ef\u4ee5\u4f7f\u7528Spring IoC\u5bb9\u5668\u4f5c\u4e3abean\u5b9a\u4e49\u7684\u6765\u6e90\u3002@Bean\u6ce8\u89e3\u544a\u8bc9Spring\uff0c\u4e00\u4e2a\u5e26\u6709@Bean\u7684\u6ce8\u89e3\u65b9\u6cd5\u5c06\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5e94\u8be5\u88ab\u6ce8\u518c\u4e3a\u5728Spring\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u4e2d\u7684bean\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2787\">@SpringBootApplication \u6ce8\u89e3\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>Spring Boot \u73b0\u5728\u5f88\u706b\u554a\uff0c\u706b\u5230\u4f60\u4e0d\u5b66\u4e60\uff0c\u53ef\u80fd\u51e0\u5e74\u540e\u4f60\u5c31\u88ab\u6dd8\u6c70\u4e86\u3002\u73b0\u5728\u5927\u7684\u516c\u53f8\uff0c\u5305\u62ec\u4e00\u4e9b\u652f\u4ed8\uff0c\u7535\u5546\u7b49\u5c0f [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[991,551,587,588,919],"class_list":["post-2787","post","type-post","status-publish","format-standard","hentry","category-java","tag-shiro-spring","tag-spring","tag-spring-boot","tag-spring-cloud","tag-spring-io-platform"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2787"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2787\/revisions"}],"predecessor-version":[{"id":2789,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2787\/revisions\/2789"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}