Spring注解驱动开发系列--(1)给容器注册组件
文章目录
1、使用xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="person" class="com.bean.Person">
<property name="age" value="20"></property>
<property name="name" value="lisi"></property>
</bean>
</beans>
2、注解方式
@Configuration
@ComponentScan(value = "com.xxx",excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class, Service.class})})
public class MainConfig {
@Bean
public Person person(){
return new Person("zeny", "45");
}
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论