spring中bean的初始化问题,路过的大侠们请求你们看一下
测试类:
package com.njty.aop;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DependsHello {
public void display() {
System.out.println("this is class DependsHello depends class Hello!!");
}
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext();
DependsHello dh = (DependsHello)ac.getBean("dh");
dh.display();
}
}
xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="dh" class="com.njty.aop.DependsHello"></bean>
</beans>
出错信息:
Exception in thread "main" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:153)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
at com.njty.aop.DependsHello.main(DependsHello.java:13)
搞不明白了,就这么个简单的小例子都错误,还找不到解决办法,很是郁闷。
哪位大侠帮助看一下,在线等,解决就给分,谢谢!
[解决办法]
cglib.jar 加到classpath下了吗
[解决办法]
Exception in thread "main" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
[解决办法]
可能是Spring的配置文件没有读入,cglib.jar的用处是面向切面,这里不加都可以。。。