简体   繁体   中英

Can't find where @Resource object is instantiated in Spring xml

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?

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.

More on @Resource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM