我在 grails 3 中有一个项目,它有一个项目 spring 依赖项,在 spring 项目中,配置了 xml beans。 grails架构中应该如何导入bens?
构建.gradle
dependencies {
compile (project(':spring-project')) { transitive = false }
}
设置.gradle
includeFlat 'spring-project'
我尝试了以下方法:
在 resources.groovy 中加载 bean:
beans = {
importBeans('path/to/beans-definition.xml')
}
在 resources.xml 中:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<import resource="path/to/beans-definition.xml" />
</beans>
除此之外,在spring项目中,配置了使用java注解的bean。 bean 在 grails 应用程序中不起作用,即使在组件扫描中设置 spring 项目包也是如此。
@ComponentScan(basePackages = ["package.spring.project.beans"])
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
但是,没有任何效果。任何帮助,将不胜感激..
最佳答案
也可以使用 grails-app/conf/spring/resources.xml 配置 Bean。在早期版本的 Grails 中,此文件是由 run-app 脚本自动为您生成的,但 resources.groovy 中的 DSL 现在是首选方法,因此现在不会自动生成。但它仍然受支持 - 您只需要自己创建它。
<bean id="myBean" class="my.company.MyBeanImpl">
<property name="someProperty" value="42" />
<property name="otherProperty" value="blue" />
进一步检查 link
关于java - 在 Grails 3 项目中为 xml bean 配置依赖注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52303982/