Ahmed M Farghali
Ahmed M Farghali

Reputation: 319

Spring-session with Hazelcast, failed to autowire HazelcastInstance

Failed to run spring-session with Hazelcast with exception:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration': 
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire method: public void org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration.setHazelcastInstance(org.springframework.beans.factory.ObjectProvider,org.springframework.beans.factory.ObjectProvider);
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [org.springframework.beans.factory.ObjectProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 
Dependency annotations: {@org.springframework.session.hazelcast.config.annotation.SpringSessionHazelcastInstance()}

I worked from the same sample in spring-session reference but using XML configuration, and already have <context:annotation-config /> in the appContext.xml.

@EnableHazelcastHttpSession 
@Configuration
public class SessionConfig {
    @Bean
    public HazelcastInstance hazelcastInstance() {
        MapAttributeConfig attributeConfig = new MapAttributeConfig()
                .setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
                .setExtractor(PrincipalNameExtractor.class.getName());

        Config config = new Config();
        config.getMapConfig(HazelcastSessionRepository.DEFAULT_SESSION_MAP_NAME) 
                .addMapAttributeConfig(attributeConfig)
                .addMapIndexConfig(new MapIndexConfig(
                        HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false));
        return Hazelcast.newHazelcastInstance(config); 
    }
}

Versions:

Upvotes: 0

Views: 1707

Answers (0)

Related Questions