问题引出
纯注解配置是相对注解+xml文件练习中,仍然有部分配置需要使用applicationContext.xml
,那么能不能使用注解替换掉所有的xml呢?Spring提供了一些新注解,可以达到这个目标。
请注意:Spring提供的这部分新注解,并非为了完全代替掉XML,只是提供了另外一种配置方案
环境跟上文xml+注解方式配置环境相同
修改的地方之一:
xml配置文件被核心控制类取代
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import javax.sql.DataSource;
import java.beans.PropertyVeto