Spring framework 3.0 safe type

In another question, I asked, expressed concern that the spring structure is not type safe. Is this true or corrected, and can you give an example of what exactly means?

+5
source share
3 answers

First of all, what does “safe type” mean for dependency injection framework. I might think that you can get a bean out of context by specifying a type, not just a bean name. Spring 3 allows this.

Otherwise, type safety means that when you can define your dependencies by type. And you can do it in all versions of spring.

- . Spring pre-3.0, beans, ( ), . Spring 3.0 ( javax.inject.Qualifier), .

- . , , @Inject List<MyService> spring.

+7

@Qualifier

bean , . JSR 330 (Inject) CDI.

@Target({ElementType.Field, ElementType.Parameter})  
@Retention(RetentionPolicy.RUNTIME)  
@Qualifier  
public @Interface Student  {  
}  

EntityDao

@Component  
@Student  
public class StudentDao implements EntityDao   {  
}  

@Component Spring, bean. @Student Spring IoC, StudentDao EntityDao , EntityDao. bean @Autowired - .

@Autowired  
@Student  
private EntityDao studentDao; // So the spring injects the instance of StudentDao here.  

, . - . http://www.coolcoder.in/2011/08/how-to-use-type-safe-dependency.html

+2

, (. ): xml beans, , , .

, Java Bean ( ), .

, - .

+1
source

All Articles