我正在使用從Apache Solr查詢數據的REST Web服務。我正在使用Spring引導+數據與Solr存儲庫。 我不知道如何互連作爲服務,存儲庫和控制器層。從控制器訪問服務層
I have the following structure
控制器:
@RestController
public class ImageSearchController {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Resource ImageService imageService;
....
}
主到SpringBootApplication:
@SpringBootApplication
public class Application extends SpringBootServletInitializer{
public static void main(String[ ] args) {
SpringApplication.run(Application.class , args);
}
}
服務:
public interface ImageService {
List<Image> searchTerm(String searchTerm);
List<Image> search(String imgSrc , String imgTitle);
List<Image> searchByImgSrc(String searchTerm);
List<Image> findAll();
}
服務默認地將Impl:
@Service
public class ImageServiceImpl implements ImageService {
@Resource
private ImageRepository repository;
@Override
public List<Image> search(String imgSrc , String imgTitle) {
return repository.findByImgSrcContainsOrImgTitleContains(imgSrc , imgTitle);
}
....
}
庫(春數據):
public interface ImageRepository extends SolrCrudRepository< Image , String > {
public List<Image> findAll();
...
}
的pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.solr/solr-solrj -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>5.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-solr -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
</dependencies>
...
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Maven Repository</name>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
如何創建bean並訪問服務層中的控制器? 如何使用其他Web服務配置solr客戶端?
UPDATE
我升級從1.4.3春天引導版本爲1.5.1,它的工作。老實說,我不明白爲什麼。 現在我得到另一個錯誤,當訪問solr時,spring數據複製solr中的核心名稱。任何想法 ?
謝謝
編輯:添加pom文件 – alves