Spring auto component scanning
- Spring Constructor Injection
- Spring Setter Injection
- Passing parameters in an aspect with XML
- Spring auto component scanning
- Spring AOP @AfterThrowing annotation example
- Before Aspect XML configuration
- AfterThrowing Aspect XML configuration
- Spring AOP @After returning annotation example
- Spring AOP @Before annotation example
- Around Aspect XML configuration
- After Aspect XML configuration
- Spring AOP terminology
- Spring AOP @Around annotation example
- Spring AOP @After annotation example
- Spring AOP annotation configuration example
- Spring MVC 3 Form Validation XML config
- Spring MVC 3 BeanNameUrlHandlerMapping
- Spring MVC 3 Form processing Annotation config
- Spring MVC 3 Form processing XML config
- AfterReturning Aspect XML configuration
- AOP examples XML configuration
- Spring dependency injection multiple syntax
- Sending Mails With Spring MailSender
- Working with Spring's Application Context
- Wiring collections with spring
- Spring 3.0 java based configuration
- Spring Java Config @Import example
- Spring MVC 3 SimpleUrlHandlerMapping
- Spring MVC 3 example XML config
- Spring MVC 3 example annotation config
- Configure hibernate with Spring XML
- Configure hibernate in Spring Annotations
- Hibernate Named Query CRUD example
- Automatically create update database with Hibernate and Spring
- Spring auto component scanning
- Sending Mails With Spring MailSender
- Spring auto component scanning
- Spring AOP @AfterThrowing annotation example
- Spring AOP @After annotation example
- Spring AOP annotation configuration example
- Spring AOP @Before annotation example
- Spring AOP @After returning annotation example
- Spring AOP @Around annotation example
- Spring auto component scanning
- Spring MVC 3 example annotation config
- Configure hibernate with Spring XML
Comments (1)
By default,
Maven configuration
We need to add the spring.jar and spring-context.jar to our classpath.
Repository
package org.camelcode.repository;
import org.springframework.stereotype.Repository;
@Repository
public class DancerDao {
public String doDance() {
return "Dancing...";
}
}
Service
@Service means that this class is a service. This can also be @Component or the other annotations. The difference between the annotations is just a naming convention. A quick glance at what type of bean this is.
package org.camelcode.service;
import org.camelcode.repository.DancerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DancerService {
@Autowired
private DancerDao dancerDao;
public String doDance(){
return dancerDao.doDance();
}
}
Application context
The <context:component-scan /> element does everything that <context:annotation-config /> does and more. It configures Spring to automatically discover beans and declare them for you. So most (or all) of your beans in your Spring application can be declared and wired without using <bean>.
The <ontext:component-scan/> element workds by scanning a package and all of its child packages, looking for classes with the right annotations. The 'base-package' attribute tells <context:component-scan/> the package to start its scan from.





Latest Posts
Latest Comments
Tag cloud
Thanks man, needed this!