使用 Spring 可以通过接口类注入 bean 列表,例如:
@Component
public class Service {
@Autowire
private List<InterfaceType> implementingBeans;
...
}
Run Code Online (Sandbox Code Playgroud)
实现此接口的所有已定义 bean 都将出现在此列表中。
基于注释的方法对我来说是不可能的,因为 Service 类位于一个不能具有 spring 依赖关系的模块中。
我需要通过 xml 配置从外部使用这种机制。
<bean id="service" class="...Service">
<property name="implementingBeans">
??? tell spring to create a list bean that resolves all beans of the interfaceType.
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
编辑:此外,有不止一个使用此服务的 spring 应用程序。所以最好的解决方案是通过 xml 配置完全处理这个 szenario。然后我可以将 xml 部分复制到所有需要它的 spriong 应用程序。
我想避免使用一种初始化 bean 来注入服务,然后必须将其复制到所有 spring 应用程序。
亲切的问候。
(使用浏览器中的JSX Transformer)从普通javascript调用react组件时,我得到一个未捕获的ReferenceError.
我尝试从我的javascript应用程序调用React.js(0.12.2)组件.我有一个JQuery document.ready处理程序来执行此操作.
它接缝,浏览器JSX编译器需要一段时间才能使用react的组件.
在这种情况下,Document.ready可能不是一个选项.
请参阅以下示例:
index.html的:
<!DOCTYPE html>
<html>
<head lang="en">
<script src="jquery-2.1.3.min.js"></script>
<script src="react-0.12.2/JSXTransformer.js"></script>
<script src="react-0.12.2/react.js"></script>
<script type="text/jsx" src="reactComponent.js"/>
<script src="app.js"/>
</head>
<body>
<div id="target"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
app.js:
$(function () {
console.log("app.js: " + typeof MyComponent);
init();
});
Run Code Online (Sandbox Code Playgroud)
component.js:
var MyComponent = React.createClass({
render: function () {
return (<div>works</div>)
}
});
function init() {
console.log("init: " + typeof MyComponent);
React.renderComponent(<MyComponent/>, document.getElementById("target"));
}
Run Code Online (Sandbox Code Playgroud)
在日志中的浏览器输出中运行此命令:
app.js: undefined
app.js: Uncaught ReferenceError: init is not defined
Run Code Online (Sandbox Code Playgroud)
但是当我通过jsx转换器加载app.js时,通过添加type="text/jsx"脚本标记,它可以工作:
app.js: …Run Code Online (Sandbox Code Playgroud)