我有两个名为simple-core-impl
和simple-core-web
的项目。
两个项目都是spring based
,并且都有一个父项目名称simple-core
。
我在simple-impl-config.xml
项目中有simple-core-impl
,在simple-web-config.xml
有simple-impl-config.xml
。
我有一个bean,它有一个类:simple service
,它有一个方法可以给我一个消息“hello World”。
我想导入simple-impl-config.xml
中的simple-web-config.xml
,以便bean可以进入simple-core-web
项目中的控制器。
simple-core-web
项目有一个simple-core-impl
项目。
那么请告诉我如何将一个项目的spring-config.xml
导入到另一个项目的spring-config.xml
中,以便首先通过导入将所有第一个bean都提供给其他项目?
我不想重写所有豆子。
答案 0 :(得分:113)
<import resource="classpath:spring-config.xml" />
<强>参考:强>
classpath:
部分解释)答案 1 :(得分:59)
肖恩答案的一小部分:
<import resource="classpath*:spring-config.xml" />
使用星号以在类路径中的任何位置弹出搜索文件'spring-config.xml'。
答案 2 :(得分:10)
出于某种原因,里卡多建议的进口对我没有用。我得到了以下声明:
<import resource="classpath*:/spring-config.xml" />
答案 3 :(得分:4)
以下是基于注释的示例:
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
mustache_render: {} // Intentionally empty, will be auto generated.
});
/**
* Helper function auto generates the configuration object for
* the mustache_render Task based on the .json files found.
*/
function generateHtml() {
var config = {},
pathsToJson = 'content/*.json';
grunt.file.expand(pathsToJson).forEach(function (filePath, index) {
// .html filename based on .json filename.
var htmlFileName = filePath.split('/').pop().split('.')[0] + '.html';
config[index] = {
files : [{
data: filePath,
template: 'templates/menu-content.mustache',
dest: 'publish/' + htmlFileName
}]
}
});
// Add the generated config object to mustache_render Task then run it.
grunt.config('mustache_render', config);
grunt.task.run(['mustache_render']);
}
grunt.loadNpmTasks('grunt-mustache-render');
grunt.registerTask('buildHtml', generateHtml);
grunt.registerTask('default', ['buildHtml']);
};
答案 4 :(得分:1)
您必须在模块A中添加模块B的jar / war,并在新的spring-module文件中添加类路径。只需添加此行
即可spring-moduleA.xml - 是资源文件夹下的模块A中的文件。通过添加此行,它将所有bean定义从模块A导入到模块B.
MODULE B / spring-moduleB.xml
import resource="classpath:spring-moduleA.xml"/>
<bean id="helloBeanB" class="basic.HelloWorldB">
<property name="name" value="BMVNPrj" />
</bean>
答案 5 :(得分:1)
<import resource="classpath*:spring-config.xml" />
这是类路径配置中最合适的一种。 特别是当您在类路径中的其他项目中搜索.xml文件时。