1、@controller 控制器(注入服务)
2、@service 服务(注入dao)
3、@repository dao(实现dao访问)
4、@component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)
@Component,@Service,@Controller,@Repository注解的类,并把这些类纳入进spring容器中管理。
下面写这个是引入component的扫描组件
<context:component-scan base-package=”com.mmnc”>
其中base-package为需要扫描的包(含所有子包)
1、@Service用于标注业务层组件
2、@Controller用于标注控制层组件(如struts中的action)
3、@Repository用于标注数据访问组件,即DAO组件.
4、@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。
@Service public class UserServiceImpl implements UserService { }
@Repository public class UserDaoImpl implements UserDao { } getBean的默认名称是类名(头字母小写),如果想自定义,可以@Service(“***”) 这样来指定,这种bean默认是单例的,如果想改变,可以使用@Service(“beanName”)
@Scope(“prototype”)来改变。可以使用以下方式指定初始化方法和销毁方法(方法名任意): @PostConstruct public void init() { }
分享到:
相关推荐
spring框架的@Resource和@Componentspring框架的@Resource和@Component
主要介绍了spring @component的作用详细介绍的相关资料,需要的朋友可以参考下
Spring @compenent注解详解,对应我的相关博客。注意,不包含相关的依赖包
Spring Boot技术知识点:如何深入理解@Component注解
主要介绍了spring @Component注解原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring注解 @Component、@Repository、@Service、@Controller区别,有兴趣的可能看一下。
Spring注解@Component、@Repository、@Service、@Controller区别.doc
Spring作为组件的接口该库在接口上添加了对Spring的@Component注释的支持: @Componentpublic interface Dummy { void dummy ();} 对于这样的接口,框架构建了一个代理对象,该代理对象将方法调用路由到方法处理程序...
Spring @讲义.txt Spring注解@Component、@Repository、@Service、@Controller区别
@RunWith(SpringJUnit4ClassRunner.class)//Spring的Junit测试,会在测试开始时,创建Spring的应用上下文 @ContextConfiguration(classes=CDPlayerSpringConfig.class)//表明配置类 public class SpringTest1 { //...
今天小编就为大家分享一篇关于Spring @Configuration和@Component的区别,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
主要介绍了spring-boot @Component和@Bean的区别详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
学生详细信息使用Spring Boot演示@ComponetScan @Component @Bean注释与使用低优先级并执行的@Bean注释相比,通过Spring IOC容器分析@component在使spring Bean对象成为对象时具有更高的优先级,并且在@component...
注解包含: 拦截器 , 过滤器 , 序列化 , @After , @AfterReturning , @AfterThrowing , @annotation , @Around , @Aspect , @Autowired , @Bean , @Before , @Component , @ComponentScan , @ComponentScans , @...
凡带有@Component,@Controller,@Service,@Repository 标志的等于告诉Spring这类将自动产生对象,而@Resource则等于XML配置中的ref,告诉spring此处需要注入对象,所以用@Resource就有了ref的功效。 要用注解注入方式...
在Spring Boot中注解@ConfigurationProperties有三种使用场景,而通常情况下我们使用的最多的只是其中的一种场景。本篇文章带大家了解一下三种场景的使用情况。 1.2 场景一 使用@ConfigurationProperties和@...
组件扫描(component scanning):Spring会自动发现应用上下文中所创建的bean。 自动装配(autowiring):Spring自动满足bean之间的依赖。 1 使用@Component定义bean 在类声明的前面使用@Component对类进行标注,这...
主要介绍了Spring实战之注入嵌套Bean操作,结合实例形式分析了嵌套Bean相关配置与使用操作技巧,需要的朋友可以参考下
Spring boot @Aspect简介使用场景列子1 (演示基本过程切点表达式切点复合运算切点...@Component public class TestAspect { /** * 声明一个切入点, 命名 pointcut1 * */ @Pointcut("execution(public java.util.M