- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究STS数据库连接。
我尝试连接我的本地数据库。
我的HomeController.java:
@Controller
public class HomeController {
@Autowired private AccountRepository AccountRepository;
//@Autowired
//private AccountDaoImpl AccountDaoImpl;
//private AccountDao AccountDao;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home";
}
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String homehome(Locale locale, Model model) {
return "home";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public @ResponseBody List<Account> getUserList() {
return AccountRepository.findAll();
//EntityManagerFactory emf = Persistence.createEntityManagerFactory("NewPersistenceUnit");
//AccountDaoImpl.entityManager = emf.createEntityManager();
//return AccountDaoImpl.getAccount();
}
//@RequestMapping(value = "/login", method = RequestMethod.POST)
//public String login(Locale locale, Model model) {
//
// EntityManagerFactory emf = Persistence.createEntityManagerFactory(
// return "login";
//}
}
AccountRepository.java:
@Service
public interface AccountRepository extends JpaRepository<Account, Long> {
}
我的帐户.java:
@Entity
@Table(name = "Account")
public class Account implements Serializable {
@Id
@Column(name = "email")
private String email;
@Column(name = "id")
private String id;
@Column(name = "password")
private String password;
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
我认为 AccountRepository.java 有 @Service,但我收到此错误。
HTTP Status 500 - Servlet.init() for servlet appServlet threw exception
type Exception report
message Servlet.init() for servlet appServlet threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet appServlet threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.myongjoon.spring.AccountRepository com.myongjoon.spring.HomeController.AccountRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myongjoon.spring.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.myongjoon.spring.AccountRepository com.myongjoon.spring.HomeController.AccountRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myongjoon.spring.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517) org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myongjoon.spring.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988) org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858) org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770) org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489) org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) note The full stack trace of the root cause is available in the Pivotal tc Runtime 3.1.2.RELEASE/8.0.26.B.RELEASE logs.
Pivotal tc Runtime 3.1.2.RELEASE/8.0.26.B.RELEASE
我想避免这个错误。
我该怎么办?
最佳答案
根本情况是:“找不到 com.myongjoon.spring.AccountRepository 类型的合格 bean”。
这是因为,您的代码看起来像是您尝试将 Spring-Data-Jpa 用于您的存储库。但这需要:
@Service
注释)和您需要启用 Spring-Data-Jpa,方法是
<springjpa:repositories base-package="com.your.repositories.package" />
(命名空间 springjpa
= http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
)或关于java - Spring BeanCreationException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35679926/
我正在使用 grails cxf-Plugin,它在本地运行良好,但是当我将它部署在 tomcat 服务器上时出现错误: ERROR context.GrailsContextLoaderListen
这是 org.xml.sax.SAXParseException;cvc-complex-type.2.4.c: The matching wildcard is strict, but no dec
有人可以告诉我如何克服 BeanCreationException 吗? 将两个变量添加到 Owner.java 后,我收到 BeanCreationException如下: @OneToMany(c
我正在尝试使用 Spring 开发 RESTful Web 服务,然后将其部署在 Google App Engine 上。该服务的客户端将是一个 Android 应用程序。我是第一次使用 spring
2011-06-13 11:45:53,128 ERROR [org.springframework.web.context.ContextLoader] Context initialization
我正在尝试从 session 工厂获取 session 以用于我的 CRUD 方法。我试图在构造函数中设置 session ,但此时 bean 尚未初始化。创建 bean 后如何初始化它? 堆栈跟踪
我正在尝试在 glassfish 上部署 netbeans java ee 项目(maven + hibernate + JSF) 我在下面收到错误。我的数据库配置没问题(从多个应用程序仔细检查),并
我正在开始使用一个小型 Spring MVC 应用程序,当我运行服务器时,出现此错误,我不知道我做错了什么,我试图理解为什么 @Autowiring 不起作用: org.springframework
我正在使用 SpringBoot 开发 Spring 4 应用程序。 在com.test.tm包中, 应用类: @SpringBootApplication @EnableJpaRepositor
我正在设置一个 Spring Boot maven 多模块项目,其中包含域层、持久层和 Web 层。 我一直在查找类似的问题,但似乎没有一个是我的情况,我怀疑这是因为该项目被划分为单独的maven模块
我有一个在本地运行的项目,但是当我尝试将其部署到 tomcat 7 服务器时,出现以下异常: ERROR: [Feb-05 16:39:30,240] web.context.ContextLoade
我尝试在 Spring 应用程序中使用 Hibernate,但项目部署时出现错误 Exception while loading the app : java.lang.IllegalStateExc
我尝试使用 spring4 和 jackrabbit 开发一些服务器程序。当我使用 JUnit 测试 Controller 类时,发生 BeanCreationExceptrion 错误。我认为这个错
我正在研究STS数据库连接。 我尝试连接我的本地数据库。 我的HomeController.java: @Controller public class HomeController { @Autow
我的 bean 定义, 异常, Caused by: org.springframework.beans.factory.BeanCreationException: Error creating
在启动过程中,我的应用程序创建了一个 bean,它在任务执行器中调度一些任务,然后在创建另一个 bean 后失败。这使我的应用程序处于不死状态,应用程序看起来正在运行但不提供功能。我想知道如何全局处理
我收到以下错误。谁能告诉我错误堆栈中的哪一行定义了我的错误? 2019-02-11 19:26:02.681 [main] ERROR o.s.web.context.ContextLoader -
我已经开始将 Spring MVC/Spring Web Tomcat 应用程序迁移到 Spring Boot。目前我正在将 xml 配置文件迁移到 java 配置。 当我尝试通过 mvn sprin
我在 Tomcat 上使用 Spring MVC。当我尝试启动 tomcat 时出现此异常: WARNING: Exception encountered during context initial
试图整合hibernate和spring,我遇到了这个错误 SEVERE: Context initialization failed org.springframework.beans.factor
我是一名优秀的程序员,十分优秀!