如何部署spring-boot微服务[已关闭]

问题描述 投票:0回答:1
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'welcomePageHandlerMapping' defined in class path resource \[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class\]: Unsatisfied dependency expressed through method 'welcomePageHandlerMapping' parameter 1: Error creating bean with name 'mvcConversionService' defined in class path resource \[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class\]: Failed to instantiate \[org.springframework.format.support.FormattingConversionService\]: Factory method 'mvcConversionService' threw exception with message: Error creating bean with name 'jsonSchemaConverter' defined in class path resource \[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class\]: Unsatisfied dependency expressed through method 'jsonSchemaConverter' parameter 1: Error creating bean with name 'associationLinks' defined in class path resource \[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class\]: Unsatisfied dependency expressed through method 'associationLinks' parameter 0: Error creating bean with name 'resourceMappings' defined in class path resource \[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class\]: Unsatisfied dependency expressed through method 'resourceMappings' parameter 0: Error creating bean with name 'repositories' defined in class path resource \[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class\]: Failed to instantiate \[org.springframework.data.repository.support.Repositories\]: Factory method 'repositories' threw exception with message: Error creating bean with name 'taskRepository' defined in com.book.todo.repository.TaskRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract org.springframework.data.domain.Page com.book.todo.repository.TaskRepository.findByAll(org.springframework.data.domain.Pageable); Reason: Failed to create query for method public abstract org.springframework.data.domain.Page com.book.todo.repository.TaskRepository.findByAll(org.springframework.data.domain.Pageable); No property 'all' found for type 'Task'



package com.book.todo.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Entity @Data public class Task {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

@Column
@NotBlank
private String name;

@Column
@NotBlank
private String description;    

}

package com.book.todo.repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; 
import org.springframework.data.querydsl.QuerydslPredicateExecutor; 
import org.springframework.data.repository.query.Param; 
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import com.book.todo.entity.Task;

@RepositoryRestResource(path = "task", collectionResourceRel = "tasks")
public interface TaskRepository extends JpaRepository<Task, Integer>, JpaSpecificationExecutor<Task>,QuerydslPredicateExecutor<Task>{

Page<Task>findyIdln(@Param(value = "id")List<Integer> eventid, Pageable Pageable);
Page<Task>findynameln(@Param("name")Collection<String> name, Pageable Pageable);

@Query(name="Task.findByName", nativeQuery = true)
List<Task>findByName(@Param("name")String name);

Page<Task>findByAll(Pageable pageable);

@Query(name="Task.findById", nativeQuery = true)
@RestResource(exported = false)
Optional<Task>findById(@Param("id")long id);

}
java
1个回答
2
投票

错误消息准确地告诉您问题所在。

Reason: Failed to create query for method public abstract 
org.springframework.data.domain.Page 
com.book.todo.repository.TaskRepository.findByAll(org.springframework.data.domain.Pageable); 
No property 'all' found for type 'Task'

使用 Spring Data 时,方法命名很重要。

findBy...
表示您要按属性查找。因此,使用
Page<Task> findByAll
,您可以告诉 Spring Data 创建查询
select * from Task where all = ?

如果你想使用分页,你需要你的存储库实现 PagingAndSortingRepository,它已经包含了

Page<T> findAll(Pageable pageable)
方法。

© www.soinside.com 2019 - 2024. All rights reserved.