スプリングブック-Springを導入するプロファイル
3941 ワード
@ImportResource:Springのプロファイルを導入して、配置ファイルの内容を有効にします.Spring BootにはSpringの配置ファイルがありません.自分で作成した配置ファイルも自動的に認識できません.Springの設定ファイルを有効にして、ロードしたいです.@Import Resourceは配置クラスに表示されています.
@ImportResource(locations={"classpath:beans.xml"})
Spring
Springのプロファイルを作成しない<?xmlversion="1.0"encoding="UTF‐8"?>
<beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring‐beans.xsd">
<bean id="helloService" class="com.atguigu.springboot.service.HelloService"></bean>
</beans>
SpringBoot容器にコンポーネントを追加する方法を紹介します.全注釈の方式1、構成類@Configration-->Springプロファイル2、@Beanを使って容器にコンポーネントを追加することを推奨します./**
* @Configuration: ; Spring
*/
@Configuration
publicclassMyAppConfig{
// ; id
@Bean
public HelloService helloService02(){
System.out.println(" @Bean ...");
return new HelloService();
}