Reputation: 129
I'm trying to find out where a java object is being instantiated. I have a Spring controller and in the controller is a dataService
field:
@SuppressWarnings("restriction")
@Controller
public class DataController {
/**
* Service for which to delegate retrieval of data
*/
@Resource
private DataService dataService;
(DataService
is an interface. The class that implements this service is DataServiceImpl
).
From my understanding, when there is @Resource above a field, it indicates that the object is instantiated using a spring bean which is usually defined in an xml file. However, i've searched my workspace for this object's name (and many variants) and looked in all the usual spring bean locations in the project but I cant find any mention of this anywhere. Does anyone know what could be happening here?
Upvotes: 0
Views: 395
Reputation: 3078
From spring framework documentation,
@Resource takes a name attribute, and by default Spring interprets that value as the bean name to be injected. If no name is specified explicitly, the default name is derived from the field name or setter method. In case of a field, it takes the field name; in case of a setter method, it takes the bean property name
In case name attribute is not provided then spring fall backs to autowiring, which will search and inject for bean of matching type.So DataServiceImpl
may be defined in spring bean xml file or annotated using @Component
.
In the exclusive case of @Resource usage with no explicit name specified, and similar to @Autowired, @Resource finds a primary type match instead of a specific named bean and resolves wellknown resolvable dependencies.
Upvotes: 1