Spring:为类路径资源注入URL [英] Spring: Inject URL for classpath resource

查看:207
本文介绍了Spring:为类路径资源注入URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以一种不会在Bean中创建对Spring的依赖的方式注入类路径资源的URL。意思是,bean不应该使用Spring的接口/类。我怎么能这样做?

I want to inject the URL of a classpath resource in a way that does not create a dependency on Spring in the Bean. Meaning, the bean should not use Spring's interfaces/classes. How can I do that?

推荐答案

Spring能够转换 classpath:... 值隐含地进入 java.net.URL

Spring is able to convert classpath:... values into java.net.URL implicitly:

public class Foo {
    private URL url;
    ...
}

<bean class = "Foo">
    <property name = "url" value = "classpath:..." />
</bean>

这篇关于Spring:为类路径资源注入URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆