Spring_通过注解配置 Bean(1)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Spring_通过注解配置 Bean(1),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2595字,纯文字阅读大概需要4分钟。
内容图文
![Spring_通过注解配置 Bean(1)](/upload/InfoBanner/zyjiaocheng/1233/b7e99fef337246b3a63b1709ad694aa1.jpg)
beans-annotation.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<!-- 指定spring IOC 容器扫描的包 -->
<!-- 可以通过 resource-pattern 指定扫描的资源 -->
<!--
<context:component-scan
base-package="com.hy.spring.beans.annotation"
resource-pattern="repository/*.class">
</context:component-scan>
-->
<!-- context:exclude-filter 子节点指定排除哪些指定表达式的组件 -->
<!-- context:include-filter 子节点指定包含哪些表达式的组件,该节点需要 use-default-filters 配合使用-->
<context:component-scan
base-package="com.hy.spring.beans.annotation"
use-default-filters="false">
<!--
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Repository"/>
-->
<!-- <context:include-filter type="annotation"
expression="org.springframework.stereotype.Repository"/>
-->
<!-- <context:exclude-filter type="assignable"
expression="com.hy.spring.beans.annotation.repository.UserRepository"/>
-->
<context:include-filter type="assignable"
expression="com.hy.spring.beans.annotation.repository.UserRepository"/>
</context:component-scan>
</beans>
TestObject.java
package com.hy.spring.beans.annotation;
import org.springframework.stereotype.Component;
@Component
public class TestObject {
}
UserController.java
package com.hy.spring.beans.annotation.controller;
import org.springframework.stereotype.Controller;
@Controller
public class UserController {
public void execute(){
System.out.println("UserController execute....");
}
}
UserRepository.java
package com.hy.spring.beans.annotation.repository;
public interface UserRepository {
public void save();
}
UserRepositoryImpl.java
package com.hy.spring.beans.annotation.repository;
import org.springframework.stereotype.Repository;
@Repository("userRepository")
public class UserRepositoryImpl implements UserRepository{
public void save() {
System.out.println("UserRepositoryImpl save....");
}
}
UserService.java
package com.hy.spring.beans.annotation.service;
import org.springframework.stereotype.Service;
@Service
public class UserService {
public void add(){
System.out.println("UserService add...");
}
}
原文:http://www.cnblogs.com/yang-hao/p/5811691.html
内容总结
以上是互联网集市为您收集整理的Spring_通过注解配置 Bean(1)全部内容,希望文章能够帮你解决Spring_通过注解配置 Bean(1)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。