Fight With Me!!!

导航

spring中的class配置不能使用properties中的字符串

1.比如在a.properties中我们声明了一个变量:

classRoom=com.wc82.ClassRoom

 

2.然后在spring的配置文件中:applicationContext.xml,有如下的配置:

<bean id="classRoom"  class="${classRoom}"  />

这样的配置是不可以的,会报错:

Caused by: java.lang.ClassNotFoundException: ${classRoom}
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:247)
	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)
	... 10 more

但以下的配置是可以的:

<property name="calssoom"  value="${classRoom}"></property>

 

posted on 2017-02-20 17:25  nickTimer  阅读(388)  评论(0编辑  收藏  举报