Merge pull request #11437 from anuragkumawat/master
JAVA-5967 : Update Introduction to Spring Data Solr
This commit is contained in:
commit
bde20380d0
|
@ -45,7 +45,7 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring-data-solr.version>2.0.5.RELEASE</spring-data-solr.version>
|
||||
<spring-data-solr.version>4.3.14</spring-data-solr.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -9,13 +9,13 @@ import org.springframework.data.solr.core.SolrTemplate;
|
|||
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableSolrRepositories(basePackages = "com.baeldung.spring.data.solr.repository", namedQueriesLocation = "classpath:solr-named-queries.properties", multicoreSupport = true)
|
||||
@EnableSolrRepositories(basePackages = "com.baeldung.spring.data.solr.repository", namedQueriesLocation = "classpath:solr-named-queries.properties")
|
||||
@ComponentScan
|
||||
public class SolrConfig {
|
||||
|
||||
@Bean
|
||||
public SolrClient solrClient() {
|
||||
return new HttpSolrClient("http://localhost:8983/solr");
|
||||
return new HttpSolrClient.Builder("http://localhost:8983/solr").build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.spring.data.solr.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -11,6 +12,8 @@ import com.baeldung.spring.data.solr.model.Product;
|
|||
|
||||
public interface ProductRepository extends SolrCrudRepository<Product, String> {
|
||||
|
||||
public Optional<Product> findById(String id);
|
||||
|
||||
public List<Product> findByName(String name);
|
||||
|
||||
@Query("id:*?0* OR name:*?0*")
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ProductRepositoryLiveTest {
|
|||
product.setId("P000089998");
|
||||
product.setName("Desk");
|
||||
productRepository.save(product);
|
||||
final Product retrievedProduct = productRepository.findOne(product.getId());
|
||||
final Product retrievedProduct = productRepository.findById(product.getId()).get();
|
||||
assertEquals(product.getId(), retrievedProduct.getId());
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class ProductRepositoryLiveTest {
|
|||
product.setName("Shirt");
|
||||
productRepository.save(product);
|
||||
|
||||
final Product retrievedProduct = productRepository.findOne(product.getId());
|
||||
final Product retrievedProduct = productRepository.findById(product.getId()).get();
|
||||
assertEquals(product.getName(), retrievedProduct.getName());
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class ProductRepositoryLiveTest {
|
|||
|
||||
productRepository.delete(product);
|
||||
|
||||
Product retrievedProduct = productRepository.findOne(product.getId());
|
||||
Product retrievedProduct = productRepository.findById(product.getId()).get();
|
||||
assertNull(retrievedProduct);
|
||||
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class ProductRepositoryLiveTest {
|
|||
wirelessCharger.setName("Phone Charging Cable");
|
||||
productRepository.save(wirelessCharger);
|
||||
|
||||
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
|
||||
Page<Product> result = productRepository.findByCustomQuery("Phone", PageRequest.of(0, 10));
|
||||
assertEquals(3, result.getNumberOfElements());
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class ProductRepositoryLiveTest {
|
|||
wirelessCharger.setName("Phone Charging Cable");
|
||||
productRepository.save(wirelessCharger);
|
||||
|
||||
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));
|
||||
Page<Product> result = productRepository.findByNamedQuery("one", PageRequest.of(0, 10));
|
||||
assertEquals(3, result.getNumberOfElements());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue