我正在研究的项目正在使用几个开源框架。每个框架都使用一些日志记录库。我的问题是最终可交付成果包含log4j(有两个不同的版本),带有回送功能的slf4j,当然还有常见的记录功能。我正在寻找解决方案,如何减少库的数量,我可以排除maven的pom文件中的日志记录库并将slf4j配置为“拦截”日志记录消息吗?
我不确定我是否完全理解依赖注入背后的想法,特别是使用Guice.
我有很大的摇摆应用程序,我想引入guice,来解耦这个应用程序.假设我在主要班级有注射器
Guice.createInjector(new BindingModule());
Application app = injector.getInstance(Application.class);
app.run();
Run Code Online (Sandbox Code Playgroud)
它有效.如果我有一些字段,让我们说在应用程序类中的JPanel,用@Inject注释然后注入它.但是如果我在Application构造函数中手动创建一些东西,那么将不会注入示例中的JTree(假设一切都配置正确).
class Application {
@Inject JPanel mainPanel //this will be injected
JPanel otherPanel;
public Application() {
otherPanel = new MyNewPanel();
mainPanel.add(otherPanel);
}
}
class MyNewPanel extends JPanel {
@Inject JTree tree; //this will not be injected
public MyNewPanel() {
add(tree);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我是否需要控制注射的所有注射物体.我不能像我一样打破控制otherPanel.