我是靠谱客的博主 风中小霸王,这篇文章主要介绍spring注册实例方式,现在分享给大家,希望可以做个参考。

1、通过xml配置

2、通过java类配置,用@ComponentScan注解

复制代码
1
2
3
4
5
@Configuration @ComponentScan(value="com.cap2") public class Cap2Config { }

3、用@bean

复制代码
1
2
3
4
@Bean public Person inint(){ return new Person("1","2"); }

4、用@import

复制代码
1
2
3
4
5
6
@Configuration //@ComponentScan(value="com.cap2",excludeFilters={@ComponentScan.Filter(type=FilterType.ANNOTATION,classes={Controller.class})},useDefaultFilters=true) @Import(value={Person.class}) public class Cap2Config { }

5、用FactoryBean

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
@Component public class FactoryBeanDemo implements FactoryBean<Person> { public Person getObject() throws Exception { // TODO Auto-generated method stub return new Person(); } public Class<?> getObjectType() { // TODO Auto-generated method stub return Person.class; }

 

最后

以上就是风中小霸王最近收集整理的关于spring注册实例方式的全部内容,更多相关spring注册实例方式内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部