View RSS Feed

Spring Framework

How to Automatically Discover Spring Beans on the Classpath

Rate this Entry
by , 11-27-2011 at 09:38 PM (1300 Views)
Since its appearance in Java 5, annotations has helped to simplify the configuration of application through component scanning. This removes the need for XML bean tags in many cases. Classes annotated as component stereotypes including the following: @Service, @Controller, @Configuration, @Component, @Repository as well as the JSR-330 annotations, such as @Named are included in the auto-scan default filter. Once auto-detected, these components become Spring beans and are automatically placed at the root of the application context.

myComponentScan.xml Enabling Component Scanning
Java Code:
<?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-3.0.xsd 
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.acme.springexamples.config.componentscan"/>
</beans>

Submit "How to Automatically Discover Spring Beans on the Classpath" to Facebook Submit "How to Automatically Discover Spring Beans on the Classpath" to Digg Submit "How to Automatically Discover Spring Beans on the Classpath" to del.icio.us Submit "How to Automatically Discover Spring Beans on the Classpath" to StumbleUpon Submit "How to Automatically Discover Spring Beans on the Classpath" to Google

Comments