无法启动Spring Boot应用程序。
存储库及其相关域
import com.vircosolutions.mobileapi.domain.Awards;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource(exported = false)
public interface AwardsRepository extends JpaRepository<Integer,
Awards> {
}
域
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
@Getter
@Setter
@Entity
@Table(name = "awards")
public class Awards implements Serializable {
private static final long serialVersionUID = -170576994834461289L;
@Id
@Column(name = "id_awards", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "id_user", nullable = false)
private Users user;
@Column (name = "rating", nullable = false)
private float rating;
@Column (name = "award_type", nullable = false)
private String awardType;
@Column (name = "award_date", nullable = false)
private Date awardDate;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Awards awards = (Awards) o;
return id == awards.id &&
Float.compare(awards.rating, rating) == 0 &&
Objects.equals(user, awards.user) &&
Objects.equals(awardType, awards.awardType) &&
Objects.equals(awardDate, awards.awardDate);
}
@Override
public int hashCode() {
return Objects.hash(id, user, rating, awardType, awardDate);
}
@Override
public String toString() {
return "Awards{" +
"id=" + id +
", user=" + user +
", rating=" + rating +
", awardType='" + awardType + '\'' +
", awardDate=" + awardDate +
'}';
}
}
主应用程序文件看起来像
@EnableSpringDataWebSupport
@SpringBootApplication
public class MobileApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return super.configure(builder);
}
public static void main(String[] args) {
SpringApplication.run(MobileApplication.class, args);
}
}
我进行了很多调试,但无法找到根本原因。 Stach跟踪如下。如果您需要任何其他文件和代码,则可以提供。任何帮助将不胜感激。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-11-22
16:30:35,341错误方法:[main] boot.SpringApplication (SpringApplication.java:842)-应用程序运行失败 org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为“ repositorySearchController”的Bean时出错 网址 [jar:文件:/home/rashid/.m2/repository/org/springframework/data/spring-data-rest-webmvc/3.0.8.RELEASE/spring-data-rest-webmvc-3.0.8.RELEASE.jar !/org/springframework/data/rest/webmvc/RepositorySearchController.class]: 通过构造函数参数0表示的不满足的依赖关系; 嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建在类中定义的名称为“ pagedResourcesAssembler”的bean 路径资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化[org.springframework.data.web.PagedResourcesAssembler]: 工厂方法'pagedResourcesAssembler'抛出异常;嵌套的 异常是org.springframework.beans.factory.BeanCreationException: 创建在类路径中定义的名称为“ pageableResolver”的bean时出错 资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.web.PageableHandlerMethodArgumentResolver]: 工厂方法'pageableResolver'抛出异常;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为“ sortResolver”的bean [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver]: 工厂方法“ sortResolver”抛出异常;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建类中定义的名称为“ repositoryRestConfiguration”的bean 路径资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.rest.core.config.RepositoryRestConfiguration]: 工厂方法'repositoryRestConfiguration'抛出异常;嵌套的 异常是org.springframework.beans.factory.BeanCreationException: 使用类路径中定义的名称“存储库”创建bean时出错 资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.repository.support.Repositories]:工厂 方法“存储库”抛出异常;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建名称为“ awardsRepository”的bean:调用init方法 失败嵌套异常是java.lang.IllegalArgumentException:不是 托管类型:java.lang.Integer类,位于 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1276) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1133) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) 〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) 〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) 〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]位于 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]位于 org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]位于 org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]位于 org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]位于 com.vircosolutions.mobileapi.MobileApplication.main(MobileApplication.java:19) [classes / :?]原因: org.springframework.beans.factory.BeanCreationException:错误 创建在类中定义的名称为“ pagedResourcesAssembler”的bean 路径资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化[org.springframework.data.web.PagedResourcesAssembler]: 工厂方法'pagedResourcesAssembler'抛出异常;嵌套的 异常是org.springframework.beans.factory.BeanCreationException: 创建在类路径中定义的名称为“ pageableResolver”的bean时出错 资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.web.PageableHandlerMethodArgumentResolver]: 工厂方法'pageableResolver'抛出异常;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为“ sortResolver”的bean [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver]: 工厂方法“ sortResolver”抛出异常;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建类中定义的名称为“ repositoryRestConfiguration”的bean 路径资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.rest.core.config.RepositoryRestConfiguration]: 工厂方法'repositoryRestConfiguration'抛出异常;嵌套的 异常是org.springframework.beans.factory.BeanCreationException: 使用类路径中定义的名称“存储库”创建bean时出错 资源 [org / springframework / data / rest / webmvc / config / RepositoryRestMvcConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化 [org.springframework.data.repository.support.Repositories]:工厂 方法“存储库”抛出异常;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建名称为“ awardsRepository”的bean:调用init方法 失败嵌套异常是java.lang.IllegalArgumentException:不是 托管类型:java.lang.Integer类,位于 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
答案 0 :(得分:3)
您以错误的顺序指定了通用类型,因此错误Not a managed type: class java.lang.Integer
尝试:
@RepositoryRestResource(exported = false)
public interface AwardsRepository extends JpaRepository<Awards, Integer> {
}
顺便说一句,并且遵循命名约定,您还应该将实体Awards重命名为Award,并相应地重命名存储库。