java.lang.IllegalArgumentException: Environment must not be null
Asked Answered
B

1

6

I try to setup a basic SolrRepository app and Have this error during ApplicationContext load :

Caused by: java.lang.IllegalArgumentException: Environment must not be null!
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.<init>(RepositoryConfigurationSourceSupport.java:50)
    at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(AnnotationRepositoryConfigurationSource.java:74)
    at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:74)
    at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:394)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:204)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:163)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:138)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:284)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:225)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    ... 28 more

Here is my ConfigClass :

@Configuration
@PropertySource("classpath:sandbox.properties")
@ComponentScan("sandbox.solr")
@EnableSolrRepositories(basePackages = { "sandbox.solr.repository" }, multicoreSupport = true)
public class StreamingSolrConf {

    @Resource
    private Environment env;

    @Bean
    public SolrServer solrServer() {
        return new HttpSolrServer(env.getRequiredProperty("solr.server.url"));
    }

    @Bean
    public SolrTemplate solrTemplate() {
        return new SolrTemplate(solrServer());
    }
}

And my repository interface :

package sandbox.solr.repository;

import org.springframework.data.solr.repository.SolrCrudRepository;

public interface SandboxRepository extends SolrCrudRepository<Document, String> {
}

Can't figure why the Environment is not injected at the right time inside the spring context. What did I miss ? Regards.

Blackhead answered 10/7, 2014 at 16:2 Comment(2)
Solved ! I was using the spring-data-solr-1.2.1.RELEASE with spring-3.2.8.RELEASE either - downgrading to spring-data-solr-1.1.3-RELEASE and stay with spring-3.2.8.RELEASE - upgrading to spring-3.2.9.RELEASE to keep spring-data-solr-1.2.1.RELEASE will solve the issue !Blackhead
Please post it as an anwser. This helped me a lot, thank you!Roadster
A
2

Just to solve this Question (see comments on original question):

He was using the spring-data-solr-1.2.1.RELEASE with spring-3.2.8.RELEASE either. Downgrading to spring-data-solr-1.1.3-RELEASE and stay with spring-3.2.8.RELEASE or upgrade to spring-3.2.9.RELEASE to keep spring-data-solr-1.2.1.RELEASE will solve the issue.

Achondroplasia answered 13/8, 2014 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.