Spring:autowired field is null?

You have to define the external class as a bean in order to make @Autowired work.

You have to define the external class as a bean in order to make @Autowired work. Also, if you use @Autowired you don't need the setter for it.

1. And the property element is useless, since it's autowired. If it was not autowired, its value would have to be an ExternalBean reference, rather than the String "com.

ExternalBean". – JB Nizet Nov 18 at 13:43 loodakrawa,hi ,thank you for point. Strange ,but still doesn't work.It's null.

– sergionni Nov 21 at 14:15 @sergionni Glad to help :) It can still be null for a various number of reasons. I is difficult for me to guess based on the relatively limited amount of info. I would suggest you to use explicit dependency injection instead of autowiring because you have a larger degree of control in that way.

I suggest reading the following: static.springsource. Org/spring/docs/2.0. X/reference/… – loodakrawa Nov 24 at 9:24.

Loodakrawa is right. A second thing that can cause a problem is, that you have a xml bean declaration for myBean and additional annotated the bean with @Service. I guess this will cause trouble as soon as use enable component scan.

I think that the better ide ais to use context path scan: Make sure that all these classes are within the package. Then mark both classes with one of the Annotations (@Repository, @Service, @Component). One of the benefits, no setter required.P.

S: If you re using scan base you don't need to declare class as bean, annotations are enough.

Danny. Lesnik , yes I have component-scan declaration in my . Xml and it's correct,but autowired field is still null.

I can't mark external lib class. – sergionni Nov 18 at 13:48 please post it. – danny.

Lesnik Nov 18 at 13:49 do I need component-scan for external lib? – sergionni Nov 21 at 14:45 @sergionni, you can't do it, because the classes of external libreries are not marked with as Repository, Service, Component. – danny.

Lesnik Nov 21 at 17:01.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions