title: Autowire JPA Repository with Hazelcast Map Store
body: <p>I am using Spring-Boot, Spring-Data/JPA with Hazelcast client/server topology. I've been trying to use a MapStore as a Write-Behind buffer for my database through HazelcastRepository. My goal is to use a JpaRepository inside my MapStore to store sessions.
  <br><br>
  My current problem is that repository is not getting @Autowired, it always returns null.</p>
  <p>Found <a href="https://stackoverflow.com/questions/51958023/spring-boot-hazelcast-mapstore-cant-autowire-repository">this post</a>  about a similar situation, but it's not working because <strong>hazelcastClientInstance.getConfig().getManagedContext()</strong> is returning null.</p>
  <p><strong>Hazelcast configuration:</strong></p>
  <pre><code>@Configuration
  @EnableHazelcastRepositories(basePackages = {&quot;com.xpto.database&quot;})
  @EnableJpaRepositories(basePackages = {&quot;com.xpto.database&quot;})
  @ComponentScan(basePackages = {&quot;com.xpto&quot;})
  public class HazelcastConfiguration {
  
  @Bean
  public SpringManagedContext managedContext() {
      return new SpringManagedContext();
  }
  @Bean
  HazelcastInstance hazelcastClientInstance(){
      // Real all configuration from hazelcast-client file
      ClientConfig clientConfig = null;
  
      try {
          clientConfig = new XmlClientConfigBuilder(&quot;hazelcast-client-config.xml&quot;).build().
                  setManagedContext(managedContext());
      } catch (IOException e) {
          e.printStackTrace();
      }
  
  
      return HazelcastClient.newHazelcastClient(clientConfig);
  }
  }
  </code></pre>
  <br>
  <br>
  <p><strong>MapStore:</strong></p>
  <pre><code>@SpringAware
  public class SessionMapStore implements MapStore&lt;String, Session&gt;, MapLoaderLifecycleSupport {
  private static final Logger LOGGER = LoggerFactory.getLogger(SessionMapStore.class);
  
  @Autowired
  private SessionsHCRepository sessionsHCRepository;
  
  
  @Override
  public void init(HazelcastInstance hazelcastClientInstance, Properties properties, String mapName) {
      hazelcastClientInstance.getConfig().getManagedContext().initialize(this);
  }
  
  @Override
  public void destroy() {
  
  }
  </code></pre>
  <br>
  <br>
  <p><strong>Repository:</strong></p>
  <pre><code>@Repository
  public interface SessionsHCRepository extends HazelcastRepository&lt;SessionDB, String&gt; {
  }
  </code></pre>
  <br>
  <br>
  <p><strong>pom file:</strong></p>
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
          &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.auth0&lt;/groupId&gt;
          &lt;artifactId&gt;java-jwt&lt;/artifactId&gt;
          &lt;version&gt;3.10.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;2.0.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
          &lt;artifactId&gt;lombok&lt;/artifactId&gt;
          &lt;version&gt;1.18.20&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
          &lt;version&gt;2.11.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;version&gt;2.11.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-dataformat-xml&lt;/artifactId&gt;
          &lt;version&gt;2.11.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
          &lt;artifactId&gt;cxf-spring-boot-starter-jaxws&lt;/artifactId&gt;
          &lt;version&gt;3.2.1&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
          &lt;version&gt;3.12.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-codec&lt;/groupId&gt;
          &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
          &lt;version&gt;1.15&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.axis&lt;/groupId&gt;
          &lt;artifactId&gt;axis&lt;/artifactId&gt;
          &lt;version&gt;1.4&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.axis&lt;/groupId&gt;
          &lt;artifactId&gt;axis-jaxrpc&lt;/artifactId&gt;
          &lt;version&gt;1.4&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;wsdl4j&lt;/groupId&gt;
          &lt;artifactId&gt;wsdl4j&lt;/artifactId&gt;
          &lt;version&gt;1.6.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.xml.rpc&lt;/groupId&gt;
          &lt;artifactId&gt;javax.xml.rpc-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-discovery&lt;/groupId&gt;
          &lt;artifactId&gt;commons-discovery&lt;/artifactId&gt;
          &lt;version&gt;0.5&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle.database.jdbc&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc8&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.hazelcast&lt;/groupId&gt;
          &lt;artifactId&gt;hazelcast-all&lt;/artifactId&gt;
          &lt;version&gt;4.2.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.hazelcast&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-hazelcast&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
      
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  </code></pre>