org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springfr
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springfr
榴莲黑芝麻糊 发表于5个月前
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springfr
  • 发表于 5个月前
  • 阅读 1
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

如题:在ctx中传入config会报错

public class UserServiceTest {
  UserService service=null;
  @Before
  public void init(){
    String[] config={"conf/spring-mybatis.xml",
          "conf/spring-mvc.xml"};
    ApplicationContext ctx=
        new ClassPathXmlApplicationContext(config);
    service=ctx.getBean("userService",UserService.class);
  }
  
  @Test//测试用户名不存在
  public void test1() throws Exception{
    NoteResult<User> result=service.checklogin("李大诗人", "123");
    System.out.println(result.getStatus());
    System.out.println(result.getMsg());
    System.out.println(result.getData());
    
  }

但是,如果在ctx中之传入一个参数"conf/spring-mybatis.xml",会报如下错误

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userService' is defined
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:570)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1114)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:279)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1121)
	at test.Service.UserServiceTest.init(UserServiceTest.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

必须都传,谷歌搜索答案得到如下提示:

Add a Bean Validation Provider dependency e.g Hibernate Validator. The Bean Validation API dependency is available on the classpath but the implementation is missing. Add the following to your pom.xml

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.2.4.Final</version>
</dependency>

在pomx.ml中添加以上代码,在ctx中传入config后测试通过

共有 人打赏支持
粉丝 0
博文 2
码字总数 311
×
榴莲黑芝麻糊
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: