java - Spring : 'org.springframework.beans.factory.UnsatisfiedDependencyException'。使用名称创建 bean 时出错

标签 java spring spring-mvc

我在spring项目中遇到了bean创建问题,我不知道该怎么办。感谢您的关注!

这是我的控制台输出:

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cartServiceImpl' defined in file [C:\Users\Ramil\eclipse-workspace\market-master\target\classes\market\service\impl\CartServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productServiceImpl' defined in file [C:\Users\Ramil\eclipse-workspace\market-master\target\classes\market\service\impl\ProductServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDAO': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at market.Application.main(Application.java:20) [classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productServiceImpl' defined in file [C:\Users\Ramil\eclipse-workspace\market-master\target\classes\market\service\impl\ProductServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDAO': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    ... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDAO': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    ... 33 common frames omitted
Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
    at org.springframework.util.Assert.isTrue(Assert.java:118) ~[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:317) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:106) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaParameters.<init>(JpaParameters.java:45) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:385) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:58) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:81) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:103) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:78) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:574) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:567) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_232]
    at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_232]
    at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1051) ~[na:1.8.0_232]
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_232]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[na:1.8.0_232]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_232]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_232]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_232]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) ~[na:1.8.0_232]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:569) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_232]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:332) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:212) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121) ~[spring-data-jpa-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    ... 44 common frames omitted

这是我的“CartServiceImpl.java”类

 package market.service.impl;

 import market.dao.CartDAO;
 import market.domain.Cart;
 import market.domain.CartItem;
 import market.domain.Product;
 import market.domain.UserAccount;
 import market.exception.UnknownEntityException;
 import market.service.CartService;
 import market.service.ProductService;
 import market.service.UserAccountService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;

 import java.util.List;
 import java.util.Optional;

 @Service
 public class CartServiceImpl implements CartService {
 private static final Logger log = LoggerFactory.getLogger(CartServiceImpl.class);

 private final CartDAO cartDAO;
 private final UserAccountService userAccountService;
 private final ProductService productService;

   public CartServiceImpl(CartDAO cartDAO, UserAccountService userAccountService, 
   ProductService productService) {
    this.cartDAO = cartDAO;
    this.userAccountService = userAccountService;
    this.productService = productService;
}

@Transactional(propagation = Propagation.SUPPORTS)
@Override
public Cart getCartOrCreate(String userEmail) {
    UserAccount account = userAccountService.findByEmail(userEmail);
    Optional<Cart> cartOptional = cartDAO.findById(account.getId());
    return cartOptional.orElseGet(() -> createCart(account));
}

private Cart createCart(UserAccount account) {
    if (log.isDebugEnabled())
        log.debug("Creating new cart for account #" + account.getId());
    return cartDAO.save(new Cart(account));
}

@Transactional
@Override
public Cart addToCart(String userEmail, long productId, int quantity) throws 
UnknownEntityException {
    Cart cart = getCartOrCreate(userEmail);
    Product product = productService.getProduct(productId);
    if (product.isAvailable()) {
        cart.update(product, quantity);
        return cartDAO.save(cart);
    } else {
        return cart;
    }
}

@Transactional
@Override
public Cart addAllToCart(String userEmail, List<CartItem> itemsToAdd) {
    Cart cart = getCartOrCreate(userEmail);
    boolean updated = false;
    for (CartItem item : itemsToAdd) {
        Optional<Product> product = productService.findOne(item.getProduct().getId());
        if (product.isPresent() && product.get().isAvailable()) {
            cart.update(product.get(), item.getQuantity());
            updated = true;
        }
    }
    return updated ? cartDAO.save(cart) : cart;
}

@Transactional
@Override
public Cart setDelivery(String userEmail, boolean deliveryIncluded) {
    Cart cart = getCartOrCreate(userEmail);
    cart.setDeliveryIncluded(deliveryIncluded);
    return cartDAO.save(cart);
}

@Transactional
@Override
public Cart clearCart(String userEmail) {
    Cart cart = getCartOrCreate(userEmail);
    cart.clear();
    return cartDAO.save(cart);
   }
}

这是“ProductServiceImpl”类

 package market.service.impl;
import market.dao.ProductDAO;
import market.domain.Distillery;
import market.domain.Product;
import market.domain.Region;
import market.exception.UnknownEntityException;
import market.service.DistilleryService;
import market.service.ProductService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

  import java.util.Comparator;
  import java.util.List;
  import java.util.Map;
  import java.util.Optional;
  import java.util.stream.Collectors;

 @Service
 public class ProductServiceImpl implements ProductService {

 private final ProductDAO productDAO;
 private final DistilleryService distilleryService;

public ProductServiceImpl(ProductDAO productDAO, DistilleryService distilleryService) {
    this.productDAO = productDAO;
    this.distilleryService = distilleryService;
}

@Transactional(readOnly = true)
@Override
public List<Product> findAll() {
    return productDAO.findAll().stream()
        .sorted(Comparator.comparing(Product::getName))
        .collect(Collectors.toList());
}

@Transactional(readOnly = true)
@Override
public Page<Product> findAll(PageRequest request) {
    return productDAO.findAll(request);
}

@Transactional(readOnly = true)
@Override
public Page<Product> findByDistillery(Distillery distillery, PageRequest request) {
    return productDAO.findByDistilleryOrderByName(distillery, request);
}

@Transactional(readOnly = true)
@Override
public Page<Product> findByRegion(Region region, PageRequest request) {
    return productDAO.findByRegionOrderByName(region, request);
}

@Transactional(readOnly = true)
@Override
public Page<Product> findByAvailability(String available, PageRequest request) {
    Page<Product> pagedList;
    if ("all".equals(available)) {
        pagedList = productDAO.findAll(request);
    } else {
        boolean availability = Boolean.parseBoolean(available);
        pagedList = productDAO.findByAvailableOrderByName(availability, request);
    }
    return pagedList;
}

@Transactional(readOnly = true)
@Override
public Product getProduct(long productId) throws UnknownEntityException {
    return productDAO.findById(productId)
        .orElseThrow(() -> new UnknownEntityException(Product.class, productId));
}

@Transactional(readOnly = true)
@Override
public Optional<Product> findOne(long productId) {
    return productDAO.findById(productId);
}

@Transactional
@Override
public void create(Product product, String distilleryTitle) {
    saveInternal(product, distilleryTitle, true);
}

@Transactional
@Override
public void update(Product product, String distilleryTitle) throws UnknownEntityException {
    Product original = getProduct(product.getId());
    product.setId(original.getId());
    saveInternal(product, distilleryTitle, original.isAvailable()); // keep original availability
}

private void saveInternal(Product changed, String distilleryTitle, boolean available) {
    Distillery distillery = distilleryService.findByTitle(distilleryTitle);
    if (distillery != null) {
        changed.setDistillery(distillery);
        changed.setAvailable(available);
        productDAO.save(changed);
    }
}
@Override
public void updateAvailability(Map<Boolean, List<Long>> productIdsByAvailability) {
    for (Map.Entry<Boolean, List<Long>> e : productIdsByAvailability.entrySet()) {
        Boolean targetAvailability = e.getKey();
        List<Product> productsToUpdate = e.getValue().stream()
            .map(this::findOne)
            .filter(Optional::isPresent)
            .map(Optional::get)
            .filter(product -> product.isAvailable() != targetAvailability)
            .collect(Collectors.toList());
        for (Product product : productsToUpdate) {
            product.setAvailable(targetAvailability);
            productDAO.save(product);
        }
    }
}

@Transactional
@Override
public void delete(long product) {
    productDAO.deleteById(product);
     }
  }

以及“ProductDAO”类。我尝试将第二个 @Param 添加到 'findByRegionOrderByName' 中,但没有帮助

package market.dao;

import market.domain.Distillery;
import market.domain.Product;
import market.domain.Region;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

 public interface ProductDAO extends CrudRepository<Product, Long>, JpaRepository<Product, Long> {

Page<Product> findByDistilleryOrderByName(Distillery distillery, PageRequest request);

@Query(value = "SELECT p FROM Product p WHERE p.distillery IN (SELECT d FROM Distillery d WHERE d.region = :region) order by p.name")
Page<Product> findByRegionOrderByName(@Param("region") Region region, PageRequest request);

Page<Product> findByAvailableOrderByName(boolean available, PageRequest request);
}

最佳答案

问题是

IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!

要修复它,只需删除 @Param 注释即可:

Page<Product> findByRegionOrderByName(Region region, PageRequest request);

关于java - Spring : 'org.springframework.beans.factory.UnsatisfiedDependencyException'。使用名称创建 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60656834/

相关文章:

java - spring mvc请求的资源不可用

java - 如何使代码发挥作用 - USACO 培训首要任务

java - 连接android时socket.io发送一些数据到服务器

Java Stack Overflow 已经折磨我很久了

java - 向已通过身份验证的用户添加新角色(无需将其注销)

spring-mvc - Spring 5.0.3 RequestRejectedException : The request was rejected because the URL was not normalized

java - 随机选择 4 种颜色?

java - spring session 只能通过一个IP访问吗?

java - Spring Boot 服务静态资源

java - 如何在Freemarker中获取请求对象