Using @Bean for managed beans

Hello,

Is it also right practice with CUBA to use the @Bean annotation for managed beans? Particularly I am using it to create a singleton bean from an environment variable I read from app.properties. Something like:

@Component(MyConfiguration.NAME)
public class MyConfiguration {

    ...

    @Bean
    public Credentials owner() {

        String privateKey = getOwnerPrivateKey();
        Credentials owner = Credentials.create(privateKey);

        return owner;
    }

    ...

    public String getOwnerPrivateKey() {
        return AppContext.getProperty("owner.privateKey");
    }
}

Thank you.

Hi,

You can choose any method of creating your beans. However, CUBA IntelliJ plugin can have difficulties finding them for its “Inject” dialog.

Thank you Konstantin, will keep it in mind.