【问题标题】:Error creating bean with name 'repositorySearchController' and pageable data创建名称为“repositorySearchController”和可分页数据的 bean 时出错
【发布时间】:2021-10-03 15:27:14
【问题描述】:

如果我理解得很好,我会遇到更多与可分页数据相关的问题。我有可分页的配置,但我更改了所有简单返回的数据(页面->列表)。我有这个错误:

org.springframework.beans.factory.UnsatisfiedDependencyException:在 URL [jar:file:/C:/Users/g.saidani/.m2/repository/org/springframework/data/ 中定义名称为“repositorySearchController”的 bean 创建错误spring-data-rest-webmvc/3.3.2.RELEASE/spring-data-rest-webmvc-3.3.2.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositorySearchController.class]:不满足的依赖关系通过构造函数参数 0;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“pagedResourcesAssembler”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.PagedResourcesAssembler]:工厂方法“pagedResourcesAssembler”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“pageableResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.PageableHandlerMethodArgumentResolver]:工厂方法“pageableResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“sortResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.SortHandlerMethodArgumentResolver]:工厂方法“sortResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositoryRestConfiguration”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.config.RepositoryRestConfiguration]:工厂方法“repositoryRestConfiguration”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositories”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.repository.support.Repositories]:工厂方法“存储库”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在创建 com.example.demo.dao.ProduitsVenteRepository 中定义的名称为“produitsVenteRepository”的 bean 时出错同时设置bean属性'mappingContext';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“jpaMappingContext”的 bean 时出错:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 java.lang.IllegalArgumentException:需要 dataSource 或 dataSourceClassName 或 jdbcUrl。 在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] 在 com.example.demo.LaBarakaBackSpringApplication.main(LaBarakaBackSpringApplication.java:51) [classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202] 在 org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.2.RELEASE.jar:2.3.2.RELEASE] 原因:org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“pagedResourcesAssembler”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.PagedResourcesAssembler]:工厂方法“pagedResourcesAssembler”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“pageableResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.PageableHandlerMethodArgumentResolver]:工厂方法“pageableResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“sortResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.SortHandlerMethodArgumentResolver]:工厂方法“sortResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositoryRestConfiguration”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.config.RepositoryRestConfiguration]:工厂方法“repositoryRestConfiguration”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositories”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.repository.support.Repositories]:工厂方法“存储库”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在创建 com.example.demo.dao.ProduitsVenteRepository 中定义的名称为“produitsVenteRepository”的 bean 时出错同时设置bean属性'mappingContext';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“jpaMappingContext”的 bean 时出错:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 java.lang.IllegalArgumentException:需要 dataSource 或 dataSourceClassName 或 jdbcUrl。 在 org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] ...省略了25个常用框架 引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.data.web.PagedResourcesAssembler]:工厂方法'pagedResourcesAssembler'抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“pageableResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.PageableHandlerMethodArgumentResolver]:工厂方法“pageableResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“sortResolver”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.web.SortHandlerMethodArgumentResolver]:工厂方法“sortResolver”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositoryRestConfiguration”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.config.RepositoryRestConfiguration]:工厂方法“repositoryRestConfiguration”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“repositories”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.repository.support.Repositories]:工厂方法“存储库”抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在创建 com.example.demo.dao.ProduitsVenteRepository 中定义的名称为“produitsVenteRepository”的 bean 时出错同时设置bean属性'mappingContext';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“jpaMappingContext”的 bean 时出错:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory;嵌套异常是 java.lang.IllegalArgumentException:需要 dataSource 或 dataSourceClassName 或 jdbcUrl。 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] ...省略了39个常用框架

【问题讨论】:

  • 相关类是(如果我理解问题的话):
  • 吞咽。这是一个巨大的错误信息。您可以包含您的代码并且只包含相关部分吗?
  • @Someone_who_likes_SE 我添加了两个相关的类,错误比我发布的要长,我只放了几行...

标签: java


【解决方案1】:
the concerned classes are (if i understand well the problem):

package com.example.demo.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.example.demo.entities.ProduitVentes;

public interface ProduitsVenteRepository extends JpaRepository<ProduitVentes, Long>{
    
    @Query(value="SELECT * FROM produit_ventes p where p.user_id= :idUser", nativeQuery = true)
    public List<ProduitVentes> findAllProduits(@Param("idUser")int idUser);

    
    @Query(value="SELECT COUNT(*) FROM produit_ventes p INNER JOIN user u ON u.id=p.user_id where u.id= :idUser", nativeQuery = true)
    public Integer findAllProduitsByUser(@Param("idUser")int idUser);

}

【讨论】:

    【解决方案2】:
    and 
    package com.example.demo.entities;
    
    import java.io.Serializable;
    import java.util.Collection;
    import java.util.List;
    
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.OneToOne;
    
    import com.fasterxml.jackson.annotation.JsonIgnore;
    import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
    import com.sun.istack.NotNull;
    @Entity
    public class ProduitVentes implements Serializable  {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy=GenerationType.IDENTITY)
        private Long id;
        private String designation;
        private double prixUnitaire;
        @JsonIgnore
        @OneToMany(mappedBy = "article", fetch = FetchType.LAZY)
        private Collection<Ventes> vente;
        
        @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
         @ManyToOne(fetch = FetchType.LAZY) 
       @JoinColumn(name = "user_id",nullable=true)
         private UserConnexion user;
        
        
        
        public ProduitVentes(String designation, double prixUnitaire, UserConnexion user) {
            super();
            this.designation = designation;
            this.prixUnitaire = prixUnitaire;
            this.user = user;
        }
        public ProduitVentes() {
            
        }
        public Long getId() {
            return id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        public String getDesignation() {
            return designation;
        }
        public void setDesignation(String designation) {
            this.designation = designation;
        }
        public double getPrixUnitaire() {
            return prixUnitaire;
        }
        public void setPrixUnitaire(double prixUnitaire) {
            this.prixUnitaire = prixUnitaire;
        }
        public Collection<Ventes> getVente() {
            return vente;
        }
        public void setVente(Collection<Ventes> vente) {
             
            this.vente = vente;
        }
    
        public UserConnexion getUser() {
            return user;
        }
    
        public void setUser(UserConnexion user) {
            this.user = user;
        }
    
        
    
        
        
    
        
    
        
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-10
      • 2021-02-21
      • 2017-06-05
      • 2017-02-26
      • 2015-02-23
      • 1970-01-01
      • 2022-07-21
      • 2017-04-22
      相关资源
      最近更新 更多