Accessing persistence while @Configuration

Hi there,

we are playing around with Cuba lately to evaluate its values for our business. So far, not bad! :wink:

However, I struggle with a tiny issue for some time now and haven’t found a solution to overcome this yet. Given I have a typical Spring configuration, in this case for spring-social:

@EnableSocial
@Configuration
public class SocialConfiguration implements SocialConfigurer {

    ...
    @Override
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
        SocialUserConnectionRepository socialUserConnectionRepository = AppBeans.get(Repositories.class).get(SocialUserConnectionRepository.class);
        UserRepository userRepository = AppBeans.get(Repositories.class).get(UserRepository.class);
        return new CustomSocialUsersConnectionRepository(socialUserConnectionRepository, userRepository, connectionFactoryLocator);
    }
}

I cannot overcome the issue of:

 Failed to instantiate [org.springframework.social.connect.UsersConnectionRepository]: Factory method 'usersConnectionRepository' threw exception; nested exception is java.lang.IllegalStateException: Application context is not initialized

How to go about this? How can I ensure the persistence layer is up and runnig when I want to configure something that relies on it?

I would expect that Springs @DependsOn should solve the issue.

In other words, is there any way to access the persistence layer inside a @Configuration annotated class?

It’s half past two here and I am still trying to find a solution to this. Very unsatisfying to go to bed without a win. =)

It looks like you’re trying to get application beans during context initialization, that’s why those services are not available to you. Is it required to pass those repositories to constructor? Can you get them later after bean initialization?

Nevermind, switched back to JHipster, everything works fine and behaves as expected.
But I guess a proxy would have helped.