package com.test.spring.support.configuration;
@configuration
public
class testconfiguration
}
<?xml version="1.0" encoding="utf-8"?>
xmlns=""
xmlns:xsi=""
xmlns:context=""
xmlns:jdbc=""
xmlns:jee=""
xmlns:tx=""
xmlns:util=""
xmlns:task=""
xsi:schemalocation="
/spring-beans-4.0.xsd
/spring-context-4.0.xsd
/spring-jdbc-4.0.xsd
/spring-jee-4.0.xsd
/spring-tx-4.0.xsd
/spring-util-4.0.xsd
/spring-task-4.0.xsd"
default-lazy-init="false">
beans>
package com.test.spring.support.configuration;
public
class testmain
}
八月 11, 2016
12:04:11 下午 org.springframework
.context
.annotation
資訊: refreshing org.springframework
.context
.annotation
@203e25d3: startup date [thu aug 11
12:04:11 cst 2016]; root of context hierarchy
spring容器啟動初始化。。。
package com.test.spring.support.configuration;
public
class testbean
public string tostring()
public
void
start()
public
void
cleanup()
}
package com.test.spring.support.configuration;
@configuration
public
class
testconfiguration
//@bean註解註冊bean,同時可以指定初始化和銷毀方法
//@bean(name="testnean",initmethod="start",destroymethod="cleanup")
@bean
@scope("prototype")
public testbean testbean()
}
package com.test.spring.support.configuration;
public
class testmain
}
package com.test.spring.support.configuration;
//新增註冊bean的註解
@component
public
class testbean
public string tostring()
}
@configuration
//新增自動掃瞄註解,basepackages為testbean包路徑
@componentscan(basepackages = "com.test.spring.support.configuration")
public
class testconfiguration
//取消@bean註解註冊bean的方式
//@bean
//@scope("prototype")
//public testbean testbean()
}
public
class testmain
}
Configuration等底層註解
一般會基本使用 知曉 full模式與lite模式 最佳實戰主要有如下兩點 配置 類元件之間無依賴關係用lite模式加速容器啟動過程,減少判斷 配置類元件之間有依賴關係,方法會被呼叫得到之前單例項元件,用full模式 1 配置類裡面使用 bean標註在方法上給容器註冊元件,預設也是單例項的 2 配置類...
底層註解 Configuration詳解
首先給出專案的目錄結構,其中需要注入的元件是user類和pet類。張三 property name userage value 25 property bean pet01 class com.hpf.boot.bean.pet name petype value 湯姆貓 property bean...
Configuration配置檔案的註解
配置類的註解。在meta inf spring.factories中宣告是配置類 檔案內容如下 org.springframework.boot.autoconfigure.enableautoconfiguration com.unit.db.starter.datasourceautoconfi...