在我设法迁移到 Spring Boot 之前,这一切正常。
在我使用版本spring-data-solr version : 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