我有個(gè)問題??????
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(); } }
運(yùn)行報(bào)錯(cuò),No bean named 'beanScope' is defined
找不到定義為beanScope的bean
2019-03-29
BeanScope類上是不是應(yīng)該加個(gè)@Service注解