【问题标题】:getting error in simple spring example在简单的弹簧示例中出错
【发布时间】:2016-12-29 21:24:03
【问题描述】:

我的 spring 库: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)

【问题讨论】:

  • TestSpring.java:12显示代码怎么样
  • 请显示主要方法。
  • 主要方法代码ideone.com/SJpSrR

标签: java spring spring-mvc dependencies


【解决方案1】:

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

例如

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多