0

This was working fine until I manage to migrate to Spring Boot.

Before I was using version spring-data-solr version : 1.4.0.RELEASE and now Boot just got version 1.3.3.

I tried to remove the spring-boot-starter-data-solr and reset to static definition but I got the same issue..

UPDATE My current 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>

My current 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());
    }
}

My current SolrRepository.java :

@Repository
public interface DocumentSolrRepository extends SolrCrudRepository<Document, Long>, DocumentSolrRepositoryCustom {
    Set<Document> findByTextContaining(@Param("text") String test);
}

My current entity using @Field attribute binded to the SolrRepository field causes the server start fail :

@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;
    }
}

The error log stacktrace :

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
eento
  • 761
  • 4
  • 20
  • 53

1 Answers1

0

You don't need to exclude or add any additional dependency. Instead you could simply define the version to be used by your spring-data projects using properties as follows:

<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>

Nothing else is needed. By the way, Fowler-SR2 was released 28.07 (its still hot).

Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106
  • defining this property didn't solve my issue.. I added extra elements in my post on my pom.xml (repositories definitions).. I currently need the Spring Solr extra dependencies so I can't only use Spring boot data solr package.. – eento Jul 31 '15 at 09:35
  • is this entity intended to be stored in using JPA and Solr? (Document seems to be a JPA `Entity` too) – Francisco Spaeth Aug 01 '15 at 10:57
  • additionally, `@Repository` isn't needed, `DocumentSolrRepository` by extending `SolrCrudRepository` is enough. – Francisco Spaeth Aug 01 '15 at 11:01