Reputation: 65
I try to connect my Springboot(v1.4.2) App with a Hazelcast Cluster to find stored data. For that I'm using a hazelcast-client instance and I created a HazelcastRepository to search my data.
The problem is that my Repository doesn't find any data. It always returns an empty list when I test with findAll() or null when I test with findOne():
Below are my Service/Repository/Domain/Configuration codes:
@Service
public class MyService {
private static final Logger log = LoggerFactory.getLogger(MyService .class);
private final MyHCRepository repository;
@Autowired
public MyService (final MyHCRepository repository) {
this.repository = repository;
}
public String get(final String name) {
List<Element> elements= repository.findByName(name);
return elements.toString();
}
}
Here is my Repo and domain:
@Repository
public interface MyHCRepository extends HazelcastRepository<Element, Integer> {
List<Element> findByName(String name);
}
@Data
@KeySpace
public class Element implements Serializable {
private Integer id;
private String name;
}
Here is my hazelcast-client config:
@Configuration
@EnableHazelcastRepositories
public class HazelcastConfiguration {
@Bean
@Qualifier("client")
public HazelcastInstance hazelcastClientInstance() {
final ClientConfig clientConfig = new ClientConfig();
final ClientNetworkConfig networkConfig = new ClientNetworkConfig();
networkConfig.setAddresses(singletonList("127.0.0.1"));
clientConfig.setNetworkConfig(networkConfig);
return HazelcastClient.newHazelcastClient(clientConfig);
}
@Bean
public KeyValueTemplate keyValueTemplate() {
return new KeyValueTemplate(new HazelcastKeyValueAdapter(hazelcastClientInstance()));
}
}
And in my pom, I use these dependencies:
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>3.6.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>spring-data-hazelcast</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<artifactId>spring-data-keyvalue</artifactId>
<groupId>org.springframework.data</groupId>
</exclusion>
<exclusion>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>spring-data-keyvalue</artifactId>
<groupId>org.springframework.data</groupId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
I got no errors, no exceptions. It's like there were no data in my Hazelcast cluster but I know there is. With my client if I connect and load a Map from the Hazelcast-Cluster like this:
client.getMap("mapsName");
then I got my Data but if I try to use the Hazelcast Repository, I dont find anything. Could someone tell me what's wrong?
Upvotes: 0
Views: 1952
Reputation: 65
Its all good, I found the problem. I just needed to associate the name of my Map with the @Keyspace Annotation inside my Domain class (Element) --> @Keyspace("myMapName")
Upvotes: 2