If the bean itself is going to determine and supply the resource path through some sort of dynamic process, it probably makes sense for the bean to use the ResourceLoader interface to load resources.Consider as an example the loading of a template of some sort,where the specific resource that is needed depends on the role of the user.If the resources are static, it makes sense to eliminate the use of the ResourceLoader interface completely, and just have the bean expose the Resource properties it needs,and expect that they will be injected into it.
What makes it trivial to then inject these properties, is that all application contexts register and use a special JavaBeans Property Editor which can convert String paths to Resource objects. So if myBean has a template property of type Resource, it can be configured with a simple string for that resource, as follows:<bean id="myBean" class="...">
Note that the resource path has no prefix, so because the application context itself is going to be used as the ResourceLoader, the resource itself will be loaded via a ClassPathResource, FileSystemResource, or ServletContextResource (as appropriate) depending on the exact type of the context.
If there is a need to force a specific Resource type to be used, then a prefix may be used. The following two examples show how to force a ClassPathResource and a Url Resource (the latter being used to access a filesystem file).
Java-Springs Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Core Java Interview Questions||JSP Interview Questions|
|Java-Springs Interview Questions||Java Servlets Interview Questions|
|JMS(Java Message Service) Interview Questions||Hibernate Interview Questions|
|Java applet Interview Questions||Java Interview Questions|
|Framework7 Interview Questions||Java collections framework Interview Questions|
|Java 8 Interview Questions||Java Programmer Interview Questions|
Introduction To Spring Framework
New Features And Enhancements In Spring 3.0
The Ioc Container
Validation, Data Binding, And Type Conversion
Spring Expression Language (spel)
Aspect Oriented Programming With Spring
Spring Aop Apis
Data Access With Jdbc
Object Relational Mapping (orm) Data Access
Marshalling Xml Using O/x Mappers
Web Mvc Framework
Integrating With Other Web Frameworks
Portlet Mvc Framework
Remoting And Web Services Using Spring
Enterprise Javabeans (ejb) Integration
Jms (java Message Service)
Task Execution And Scheduling
Dynamic Language Support
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.