这很好,直到我设法迁移到Spring Boot。
在我使用版本 spring-data-solr版本:1.4.0.RELEASE 之前,现在 Boot刚刚获得版本1.3.3 。
我尝试删除 spring-boot-starter-data-solr 并重置为静态定义,但我遇到了同样的问题..
更新我当前的 pom.xml :
<project>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<repositories>
<repository>
<id>excilys-release</id>
<url>http://repository.excilys.com/content/repositories/releases</url>
</repository>
<repository>
<id>repo2_maven_org</id>
<url>http://repo2.maven.org/maven2</url>
</repository>
<repository>
<id>maven-restlet</id>
<url>http://maven.restlet.com</url>
</repository>
</repositories>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring Solr -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.10.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
</exclusions>
</dependency>
</project>
我当前的 SolrConfig.java :
@Configuration
@EnableSolrRepositories(basePackages = "com.repository.solr")
@ComponentScan("com.repository.solr")
public class SolRConfig {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public static final String PROPERTY_SOLR_SERVER_CORE = "solr.core";
@Resource
private Environment environment;
@Resource OgcParameters ogcParameters;
@Bean
public SolrServer solrServer() {
final OgcParameters.slr slr = ogcParameters.slr();
if (!environment.containsProperty(PROPERTY_SOLR_SERVER_CORE)) {
logger.warn("You are running on the default solr core, create or edit the application.properties to avoid this behaviour");
}
String solrHostWithCoreIfNecessary = slr.host()
.concat(slr.core());
return new HttpSolrServer(solrHostWithCoreIfNecessary);
}
@Bean
public SolrOperations solrTemplate() throws ParserConfigurationException, SAXException, IOException {
return new SolrTemplate(solrServer());
}
}
我当前的 SolrRepository.java :
@Repository
public interface DocumentSolrRepository extends SolrCrudRepository<Document, Long>, DocumentSolrRepositoryCustom {
Set<Document> findByTextContaining(@Param("text") String test);
}
我当前的实体使用绑定到SolrRepository字段的@Field
属性导致服务器启动失败:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class Document {
private Long id;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DOCUMENT_SEQ")
@SequenceGenerator(name="DOCUMENT_SEQ", sequenceName="DOCUMENT_SEQ")
public Long getId() {
return id;
}
public Document setId(Long id) {
this.id = id;
return this;
}
/* SOLR Specific Fields */
@Field("text")
private String text;
@Transient @JsonIgnore
public String getText() {
return text;
}
public Document setText(String text) {
this.text = text;
return this;
}
}
错误日志堆栈跟踪:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicantController': Injection of resource dependencies failed;
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [text] on this ManagedType [com.entity.Document]
at org.hibernate.jpa.internal.metamodel.AbstractManagedType.checkNotNull(AbstractManagedType.java:144)
at org.hibernate.jpa.internal.metamodel.AbstractManagedType.getAttribute(AbstractManagedType.java:130)
at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:475)
at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:199)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:146)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:86)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:44)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:110)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.<init>(PartTreeJpaQuery.java:230)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:64)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94)
... 68 more
答案 0 :(得分:0)
您不需要排除或添加任何其他依赖项。相反,您可以使用以下属性定义spring数据项目要使用的版本:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<properties>
<spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
...
</dependencies>
不需要其他任何东西。顺便说一句,Fowler-SR2于28.07发布(仍然很热)。