五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

@SpringBootApplication的使用

2019-12-26 17:34 作者:觴翊の澤  | 我要投稿

地址:https://www.cnblogs.com/MaxElephant/p/8108140.html

之前用戶使用的是3個注解注解他們的main類。分別是@Configuration,@EnableAutoConfiguration,@ComponentScan。由于這些注解一般都是一起使用,spring boot提供了一個統(tǒng)一的注解@SpringBootApplication。

@SpringBootApplication = (默認(rèn)屬性)@Configuration + @EnableAutoConfiguration + @ComponentScan。

@SpringBootApplication?
public?class?ApplicationMain {?
????public?static?void?main(String[] args) {?
????????SpringApplication.run(Application.class, args);?
????}?
}

?

分開解釋@Configuration,@EnableAutoConfiguration,@ComponentScan。

1、@Configuration:提到@Configuration就要提到他的搭檔@Bean。使用這兩個注解就可以創(chuàng)建一個簡單的spring配置類,可以用來替代相應(yīng)的xml配置文件。

<beans>?
????<bean id =?"car"?class="com.test.Car">?
????????<property name="wheel"?ref =?"wheel"></property>?
????</bean>?
????<bean id =?"wheel"?class="com.test.Wheel"></bean>?
</beans>?

?相當(dāng)于:


@Configuration?
public?class?Conf {?
????@Bean?
????public?Car car() {?
????????Car car =?new?Car();?
????????car.setWheel(wheel());?
????????return?car;?
????}?
????@Bean??
????public?Wheel wheel() {?
????????return?new?Wheel();?
????}?
}

?

@Configuration的注解類標(biāo)識這個類可以使用Spring IoC容器作為bean定義的來源。@Bean注解告訴Spring,一個帶有@Bean的注解方法將返回一個對象,該對象應(yīng)該被注冊為在Spring應(yīng)用程序上下文中的bean。

2、@EnableAutoConfiguration:能夠自動配置spring的上下文,試圖猜測和配置你想要的bean類,通常會自動根據(jù)你的類路徑和你的bean定義自動配置。

3、@ComponentScan:會自動掃描指定包下的全部標(biāo)有@Component的類,并注冊成bean,當(dāng)然包括@Component下的子注解@Service,@Repository,@Controller。

?


@SpringBootApplication的使用的評論 (共 條)

分享到微博請遵守國家法律
克东县| 来安县| 东至县| 太原市| 佛山市| 临猗县| 平定县| 南靖县| 西畴县| 台中县| 乡城县| 理塘县| 汉川市| 双辽市| 明星| 琼中| 休宁县| 麻江县| 收藏| 麻栗坡县| 奉化市| 诸城市| 辰溪县| 阿拉善左旗| 缙云县| 泰顺县| 龙井市| 黎城县| 峨眉山市| 镇安县| 宿松县| 莱州市| 峡江县| 安西县| 三河市| 蒙城县| 句容市| 霍州市| 雷州市| 白河县| 大渡口区|