我想以一种不在Bean中创建对Spring的依赖的方式注入类路径资源的URL.意思是,bean不应该使用Spring的接口/类.我怎样才能做到这一点?
axt*_*avt 15
Spring能够将classpath:...值转换为java.net.URL隐式:
public class Foo {
private URL url;
...
}
Run Code Online (Sandbox Code Playgroud)
.
<bean class = "Foo">
<property name = "url" value = "classpath:..." />
</bean>
Run Code Online (Sandbox Code Playgroud)
继 axtavt 的回答之后,如果您允许自己在 bean 中使用 Spring 注释,则可以这样做:
@Value("classpath:myClasspathLocation") private URL url;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17789 次 |
| 最近记录: |