`

<context:component-scan/> 标签解析

 
阅读更多

在spring 中<context:component-scan/>作用就是帮我们自动装配Bean,变处理好依赖关系。

首先  <context:component-scan/>是属于CustomElement,后来spring扩展补充的由ContextNamespaceHandler来解析命名空间然后由ClassPathBeanDefinitionScanner来扫描类路径来加载Bean。

然后会加载相应的BeanPostProcessor用于再生成bean时进行处理

1:ConfigurationClassPostProcessor 用来处理带有@Configuration注解的类

2:AutowiredAnnotationBeanPostProcessor

 用来处理@Autowired ,@Value,@Inject注解的依赖注入功能

3:RequiredAnnotationBeanPostProcessor

用来处理带有@Required注解的雨来注入

4:CommonAnnotationBeanPostProcessor

处理javax.annotation 包下注解@PostConstruct和@PreDestroy等

5:PersistenceAnnotationBeanPostProcessor

提供对jpa 相关注解的支持如@PersistenceUnit@PersistenceContext等

 

分享到:
评论

相关推荐

    Spring 报错:元素 "context:component-scan" 的前缀 "context" 未绑定的问题解决

    然而,在配置过程中,如果遇到“元素 'context:component-scan' 的前缀 'context' 未绑定”的错误,这意味着Spring无法识别和解析这个元素,因为缺少了对应的命名空间定义。 这个问题的根源在于XML配置文件中没有...

    spring_MVC源码

    12. &lt;context:component-scan base-package="com.mvc.controller" /&gt; 13. &lt;!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --&gt; 14. &lt;bean class="org.springframework.web.servlet.mvc.annotation...

    Test05_Spring_Context_XML.rar

    在XML配置文件中,我们可以通过`&lt;context:component-scan&gt;`标签来扫描指定包下的类,以便自动发现并注册bean: ```xml &lt;context:component-scan base-package="com.example"/&gt; ``` 最后,Spring提供了多种方式来...

    简单的 Eclipse环境下搭建spring的范例

    &lt;context:component-scan base-package="com.example.springdemo" /&gt; &lt;mvc:annotation-driven /&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; ...

    spring mvc基础

    &lt;context:component-scan base-package="com.example.controller"/&gt; &lt;!-- 其他配置... --&gt; &lt;/beans&gt; ``` - **2.3 Spring 配置文件** Spring配置文件通常用于管理Bean的生命周期,以及配置数据源、事务管理等...

    SpringMvc HelloWorld

    &lt;context:component-scan base-package="com.yourpackage"/&gt; &lt;mvc:annotation-driven/&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/...

    使用Maven构建Spring MVC项目的简单示例

    &lt;context:component-scan base-package="com.tan.maven.springmvc" /&gt; &lt;mvc:annotation-driven /&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix...

    springMVC框架搭建及详解

    &lt;context:component-scan base-package="com.example.controller"/&gt; &lt;!-- 视图解析器 --&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property ...

    Spring MVC3构建Web应用详解

    &lt;context:component-scan base-package="com.adobocode.controller" /&gt; &lt;!-- 配置视图解析器 --&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix...

    SpringMVC 学习总结

    &lt;context:component-scan base-package="com.example.controller"/&gt; &lt;mvc:annotation-driven/&gt; &lt;!-- 其他配置 --&gt; &lt;/beans&gt; ``` 以上就是SpringMVC框架的基本介绍及其搭建过程。通过学习这些内容,开发者可以...

    springmvc+mybatis+oracle

    &lt;context:component-scan base-package="com.example.controller" /&gt; &lt;!-- 自定义拦截器配置 --&gt; &lt;mvc:interceptors&gt; &lt;bean class="com.example.interceptor.MyInterceptor" /&gt; &lt;/mvc:interceptors&gt; &lt;/beans&gt; ...

    集成springmvc spring hibernate的配置

    &lt;/context:component-scan&gt; ``` 2. **数据库连接配置**:我们需要从`jdbc.properties`文件中读取数据库连接信息。使用`context:property-placeholder`标签将属性文件加载到Spring上下文中。然后,配置数据源`...

    开发框架搭建

    &lt;context:component-scan base-package="cn.springmvc"/&gt; &lt;!-- 配置MyBatis SqlSessionFactory --&gt; &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt; &lt;property name=...

    Springboot项目整合JSP页面

    &lt;context:component-scan base-package="com.cloud.JspDemo"/&gt; &lt;mvc:annotation-driven/&gt; &lt;!-- 添加视图解析器 --&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; ...

    IDEASSM框架实战CRUDSSM整合配置MyBatis逆向工程.docx

    &lt;context:component-scan base-package="com.example.demo.controller" /&gt; &lt;!-- 视图解析器 --&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" ...

    非maven-SSM (下) springMVC部分 手牵手操作.实在不能再详细了 多次测试

    &lt;context:component-scan base-package="com.example.service" /&gt; &lt;!-- 配置数据源 --&gt; &lt;bean id="dataSource" class="..."/&gt; &lt;!-- 配置事务管理器 --&gt; &lt;bean id="transactionManager" class="..."/&gt; &lt;!-- ...

    SpringMVC入门

    - **扫描包含Controller的包**:通过`&lt;context:component-scan&gt;`元素指定需要扫描的包。 - **不处理静态资源**:通过`&lt;mvc:default-servlet-handler/&gt;`让Servlet容器处理静态资源。 - **启用注解驱动**:使用`&lt;mvc:...

    maven搭建SSM框架

    &lt;context:component-scan base-package="com.example.ssm.controller" /&gt; ``` 3. **Web.xml 配置**: - 配置`ContextLoaderListener`和`DispatcherServlet`。 - 示例代码如下: ```xml &lt;listener&gt; &lt;listener...

    spring3零配置注解实现Bean定义(包括JSR-250、JSR-330)

    通过使用`&lt;context:component-scan&gt;`标签配合特定的注解(如`@Component`、`@Service`等),可以完全避免XML配置的使用,从而让开发者能够更加专注于业务逻辑的实现。同时,Spring对JSR-250和JSR-330等标准的支持也...

    java整合SSM框架

    &lt;context:component-scan base-package="com.example.controller"/&gt; &lt;!-- 配置静态资源 --&gt; &lt;mvc:resources mapping="/resources/**" location="/resources/"/&gt; &lt;!-- 视图解析器 --&gt; &lt;bean class="org.spring...

Global site tag (gtag.js) - Google Analytics