Giter Site home page Giter Site logo

spring-and-bsaf's Introduction

spring-and-bsaf

This small application demonstrates how to make the Spring Framework and the Better Swing Application Framework (BSAF) work together. We leave the question of why you would like to do that to another time. ;-)

The problem with combining the two frameworks is that they both want to create the singleton instance of the main application class. BSAF requires you to create and run your Application subclass by calling the static launch method. Spring of course wants to create all managed beans as part of the application context.

The solution is to introduce a @Configuration class with a method that creates a Spring bean from the BSAF application instance. In the Application subclass, you let BSAF create the application:

public static void main(String[] args) {
    // Create the singleton application instance using BSAF here
    launch(BsafApplication.class, args);
}

In the @Configuration class, you create a bean that just returns the singleton instance:

@Bean
public BsafApplication application() {
    // Return the singleton application instance as a Spring bean here
    return (BsafApplication) Application.getInstance();
}

This enables the application instance to be injected into other classes, even though it was created before the application context was loaded. You just have to be careful to not access the application bean before the application instance has been created by calling launch. Otherwise, BSAF will create a dummy instance that is not compatible with your real Application subclass.

For a Kotlin version of this project, please see spring-and-bsaf-kotlin.

spring-and-bsaf's People

Contributors

dykstrom avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

kansassamurai

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.