I hope there is more generic way to load the resource.
The javax.annotation.Resource focus on JNDI resources.
I hope there is a way like this.
@Resource("classpath*:/app.properties")
Properties pro;
@Resource("jndi:java:/jboss/datasources/ExampleDS")
DataSource dataSource;
@Resource("http://localhost:8080/myapp/user/1.json")
JsonObject json;
@Resource("file:///D:/app.properties")
File pro;
or
@Resource(value="xyz:myresousepath", resolver=MySolver.class )
MyObject dataSource;
the value is <protocol>:<resourcespath>...and an optional custom
ResourceResolver(by default, should resgister the some generic resource
resovler by protocol, such as classpath, and jndi, and all url based. )
to discovery the resource, and convert the resource result to required
object.
Hantsy
On 8/19/2013 16:09, Christian Kaltepoth (JIRA) wrote:
> [
> https://issues.apache.org/jira/browse/DELTASPIKE-399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13743617#comment-13743617
> ]
>
> Christian Kaltepoth commented on DELTASPIKE-399:
> ------------------------------------------------
>
> I agree with Gerhard that we should avoid name clashes. What about
> @ClasspathResource?
>
> What do you think about extending what Solder provided by supporting
> injection of other types than URL and InputStream? We could provide an SPI to
> allow users to extend the types that are supported.
>
> Imagine this example. A user wants to load a FreeMarker template from the
> classpath. Wouldn't it be nice to be able to do something like this:
>
> @Inject
> @ClasspathResource(name="template.ftl", loader=TemplateLoader.class)
> private Template myTemplate;
>
> Where TemplateLoader is an implementation of an interface like this:
>
> public interface ResourceLoader<T> {
> T load(URL url);
> }
>
> Actually I don't think the user will have to explicitly name the loader to
> use. This could be done automatically.
>
> Thoughts?
>
>> Incorporate Solder's ResourceLoader features into DeltaSpike
>> ------------------------------------------------------------
>>
>> Key: DELTASPIKE-399
>> URL: https://issues.apache.org/jira/browse/DELTASPIKE-399
>> Project: DeltaSpike
>> Issue Type: New Feature
>> Components: Core
>> Affects Versions: 0.4
>> Reporter: Aaron Siri
>> Assignee: John D. Ament
>> Priority: Minor
>> Fix For: 0.6
>>
>>
>> Seam 3's Solder module had some nice resource loading functionality within
>> the org.jboss.solder.resourceLoader packages. With it you could do the
>> following:
>> // Load a properties file
>> @Inject @Resource("app.properties")
>> private Properties appProperties;
>> or:
>> @Inject
>> private ResourceProvider resourceProvider
>> public Properties getHostProperties() {
>> String hostname = java.net.InetAddress.getLocalHost().getHostName();
>> return resourceProvider.loadPropertiesBundle(hostname + ".properties");
>> }
> --
> This message is automatically generated by JIRA.
> If you think it was sent incorrectly, please contact your JIRA administrators
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>