- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试访问我的服务时抛出异常,我使用 spring roo 创建了我的 spring 数据 jpa 存储库,该存储库生成了文件 applicationContext-jpa.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<repositories base-package="org.bixin.dugsi" />
</beans:beans>
我的 applicationContext.xml 位于同一目录 META-INF/spring/
中,我确保包含组件扫描
<context:component-scan base-package="org.bixin.dugsi">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
我如何使用它的测试用例如下:
@RooIntegrationTest(entity = UserAccount.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/applicationContext.xml" })
public class UserAccountIntegrationTest extends AbstractJUnit4SpringContextTests {
@PersistenceUnit(unitName = "persistenceUnit")
private EntityManagerFactory factory;
PasswordService testsPasswordService = new CustomPasswordService();
@Autowired
private AccountSettingsRepository accountSettingsRepository;
@Autowired
private AccountService accountService;
@Test
public void testAccount(){
accountService.saveAccountSettings(accountSettings);
Assert.assertNotNull(accountSettings);
}
我不知道是什么导致了这个异常,我告诉它在哪里可以找到服务实现和存储库。完整的堆栈跟踪如下:
2012-07-01 14:11:06,661 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@512d8ecd] to prepare test instance [org.bixin.dugsi.domain.UserAccountIntegrationTest@97d01f]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.bixin.dugsi.repositories.AccountSettingsRepository org.bixin.dugsi.service.AccountServiceImpl.accountSettingsRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.bixin.dugsi.repositories.AccountSettingsRepository] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.bixin.dugsi.repositories.AccountSettingsRepository org.bixin.dugsi.service.AccountServiceImpl.accountSettingsRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.bixin.dugsi.repositories.AccountSettingsRepository] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 39 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.bixin.dugsi.repositories.AccountSettingsRepository] 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)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 41 more
2012-07-01 14:11:06,666 [main] DEBUG org.springframework.test.context.support.DirtiesContextTestExecutionListener - After test class: context [[TestContext@1ebcda2d testClass = UserAccountIntegrationTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@6ee0a386 testClass = UserAccountIntegrationTest, locations = '{classpath:META-INF/spring/applicationContext.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]], dirtiesContext [false].
帐户设置存储库
打包 org.bixin.dugsi.repositories;
import java.util.List;
import org.bixin.dugsi.domain.AccountSettings;
import org.springframework.roo.addon.layers.repository.jpa.RooJpaRepository;
@RooJpaRepository(domainType = AccountSettings.class)
public interface AccountSettingsRepository {
}
上下文applicationContext-Jpa.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<repositories base-package="org.bixin.dugsi.repositories" />
</beans:beans>
最佳答案
检查您的 applicationContext-jpa.xml
是否由您的主上下文加载。
为此,请检查您的 applicationContext.xml
是否包含:
<import resource="applicationContext-jpa.xml"/>
关于java - BeanCreationException NoSuchBeanDefinitionException 使用 Spring roo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11284935/
我正在使用 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
我是一名优秀的程序员,十分优秀!