简体   繁体   中英

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. 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?

Spring provides an IoC container in the form of an ApplicationContext . 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. Read the official documentation on how to do either, here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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