carlspring
carlspring

Reputation: 32627

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?

Upvotes: 0

Views: 78

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280000

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.

Upvotes: 4

Related Questions