我正在使用jpa存储库进行自定义查询。但是我遇到了错误
错误日志:
通过字段“ loginService”表示的不满意的依赖关系;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'loginService'的bean时出错:通过字段'loginServiceImpl'表示的不满足的依赖关系;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为'loginServiceImpl'的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:方法公共抽象java.util.List com.facultyProject.faculty_project.service.LoginServiceImpl.fetchByLoginId(java.lang.String,java.lang.String)
的查询验证失败
存储库类
package com.facultyProject.faculty_project.service;
import com.facultyProject.faculty_project.dao.Login;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface LoginServiceImpl extends JpaRepository<Login,Long> {
@Query("select e FROM Login e WHERE e.login_id =(:loginId) and e.password=(:password)")
List<Login> fetchByLoginId(@Param("loginId") String loginId, @Param("password") String password);
}
错误日志
2019-01-23 11:44:15.803错误8796-[nio-8181-exec-3] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()在路径为[]的上下文中引发异常[请求处理失败;嵌套异常是java.lang.IllegalStateException:找不到根本原因的类java.lang.Boolean]的主构造函数或默认构造函数
java.lang.NoSuchMethodException:java.lang.Boolean。() 在java.lang.Class.getConstructor0(Class.java:3082)〜[na:1.8.0_171] 在java.lang.Class.getDeclaredConstructor(Class.java:2178)〜[na:1.8.0_171] 在org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:208)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:84)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:131)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在javax.servlet.http.HttpServlet.service(HttpServlet.java:661)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)〜[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在javax.servlet.http.HttpServlet.service(HttpServlet.java:742)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)〜[tomcat-embed-websocket-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE] 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)〜[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)上[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:806)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1498)[tomcat-embed-core-8.5.34.jar:8.5.34] 在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)上[tomcat-embed-core-8.5.34.jar:8.5.34] 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[na:1.8.0_171] 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)[na:1.8.0_171] 在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)[tomcat-embed-core-8.5.34.jar:8.5.34] 在java.lang.Thread.run(Thread.java:748)[na:1.8.0_171]
该项目的github链接是
https://github.com/dishankgoyal/springsBoot/tree/master/faculty_project
答案 0 :(得分:1)
该错误消息表明JPA查询的语法存在问题。尝试删除参数周围的括号,并确保e.login_id和e.password是实体类Login中的属性名称(不是数据库列名称)。
答案 1 :(得分:0)
实体中没有名为 login_id 的字段,因此在查询
login_name或id
代替login_id >
您不需要使用自定义查询(@Query(...)
)
使用方法findByLogin_nameAndPassword(String login_name, String password);
代替
LoginServiceImpl
应该是 Service接口的实现,但是您将其用作存储库并保存在服务包中,这是构造代码库的错误方法。
答案 2 :(得分:0)
注释@Service应该标注到服务实现类而不是接口上。