在简单的春天例子中得到错误

时间:2016-08-23 07:11:09

标签: java spring spring-mvc dependencies

我的春季图书馆:3.2.0

Xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">


<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/security
                           http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<bean id = "res_Bean" class = "Restaurant"
<property name="welcomeNote" value="welcome to my restaurant"/>

</bean>

</beans>

我试图解决,但我没有得到正确的答案。

  

线程“main”中的异常java.lang.IllegalStateException:BeanFactory   未初始化或已经关闭 - 在访问之前调用'刷新'   bean通过ApplicationContext在   org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)     在   org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)     在TestSpring.main(TestSpring.java:12)

1 个答案:

答案 0 :(得分:1)

当您定义bean属性类时,应该等于该类的完整包路径。

例如

<bean id="restaurant" class="com.models.Restaurant"> 
      <property <property name="welcomeNote" value="welcome to my restaurant"/>>
</bean>