ham*_*est 2 grails groovy resources spring classpath
从我们的Grails/Groovy应用程序中,我们需要使用遗留Java服务类中的服务,其构造函数具有org.springframework.core.io.Resource类型的参数,例如
public ServiceClass(Resource someResource)
Run Code Online (Sandbox Code Playgroud)
我们需要使用Spring DSL将服务类的实例注入到我们应用程序的Groovy类中,资源引用/ src/main/resources中的XML文件.我试图为此目的创建Spring配置,但到目前为止我找不到一个可行的解决方案.配置文件的相关部分如下所示
beans = {
xmlns aop:"http://www.springframework.org/schema/aop",
sec:"http://www.springframework.org/schema/security",
context:"http://www.springframework.org/schema/context"
serviceClass(com.somepackage.ServiceClass) {
//here we need to refer to the constructor arg XML file some way
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了各种教程中的多种语法,例如关闭beanDefinition.constructorArgs,但遗憾的是到目前为止还没有成功.虽然应用程序编译(grails:war)和启动(grails:run-app)都没有表明bean接线存在任何问题,但当应用程序实际加载到浏览器中时,我们收到一个NPE,说明我们的Groovy类到哪个注入服务类,是一个null对象.所以看起来豆接线毕竟不成功.任何帮助表示赞赏
在解决了项目设置本身和多次清理/重新编译的各种问题后,似乎以下两种方法都可以
serviceClass(com.somepackage.ServiceClass, '/WEB-INF/constructor-arg-xml-file.xml') {}
Run Code Online (Sandbox Code Playgroud)
和
serviceClass(com.somepackage.ServiceClass) { bean ->
bean.constructorArgs = [
'/WEB-INF/constructor-arg-xml-file.xml'
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1938 次 |
| 最近记录: |