supernova
supernova

Reputation: 3271

Using Java Singleton class in Spring as prototype

I have a class which is plain Java Singleton.

public class MySingleton {

    Private static instance  = new MySingleton();

    private MySingleton(){}

    public static getInstance(){
       return instance;
    }

Now if I use this singleton class as a bean in Spring in prototype scope will Spring create multiple instance of this pure singleton class?

<bean id="supposedToBeSingleton" class="MySingleton" scope="prototype" />

Upvotes: 0

Views: 224

Answers (2)

Sharif
Sharif

Reputation: 9

Your definition of spring is incorect thats why it is bringing errors , you should define as this Where by YourClassName stands for your class(parent or child class)

Upvotes: 1

Har Krishan
Har Krishan

Reputation: 273

Logically Spring will not use

         public static getInstance(){
           return instance;
         }

which is returning the singleton so it will return prototype using the default constructor. But to be sure you can just run the test.

Upvotes: 0

Related Questions