简体   繁体   English

在Webapp外部连接Spring bean的最简单/正确的方法是什么?

[英]What's the easiest/proper way to wire Spring beans outside a webapp?

I am developing an non-web application and I would like to set up Spring in it. 我正在开发一个非Web应用程序,我想在其中设置Spring。 I would like to have minimal configuration that supports auto-wiring. 我想拥有支持自动接线的最小配置。 What's the proper way to do this? 正确的方法是什么? Do I need to implement my own ApplicationContext loading mechanism, or is there something better I could do? 我需要实现自己的ApplicationContext加载机制,还是可以做得更好?

Spring provides an IoC container in the form of an ApplicationContext . Spring提供了ApplicationContext形式的IoC容器。 However, you need to implement your own mechanism for creating the container. 但是,您需要实现自己的机制来创建容器。 But that can be pretty simple 但这很简单

public class Start {
    public static void main(String[] args) {
        ApplicationContext context = ...// whichever flavor you want
        // maybe start some threads, possibly managed by the IoC container
    }
}

The container itself can either use XML configuration or a programatic one. 容器本身可以使用XML配置,也可以使用程序配置。 Read the official documentation on how to do either, here . 此处阅读有关如何执行操作的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM