只想敲个代码
2019-03-22 21:19
package main.java.com.xiaodao.bean; public class BeanScope { public void say(){ System.out.println("BeanScope say:" +this.hashCode()); } } <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" > <bean id="beanScope" class="main.java.com.xiaodao.bean.BeanScope" scope="singleton"></bean> </beans> import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; import main.java.com.xiaodao.bean.BeanScope; import test.java.com.xiaodao.test.base.UnitTestBase; @RunWith(BlockJUnit4ClassRunner.class) public class TestBeanScope extends UnitTestBase { public TestBeanScope() { super("classpath*:spring-beanscope.xml"); } @Test public void testSay() { BeanScope beanScope = super.getBean("beanScope"); beanScope.say(); } }
运行报错,No bean named 'beanScope' is defined
找不到定义为beanScope的bean
BeanScope类上是不是应该加个@Service注解
Spring入门篇
268785 学习 · 963 问题
相似问题