在web.xml中定义了以下内容
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:abc/xml/spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
如果将上面内容中的<context-param>...</context-param>这个去掉JBOSS5启动时会提示找不到applicationContext.xml,加上则没事,由此是不是可以说加上这段内容applicationContext.xml已被加载,如果已被加载可为什么在用getBean获取bean时却提示找不到这个bean定义了一个servlet,在这个servlet的init()中获取bean
public void init(){
//getBean("bean名称");
//提示找不到这个bean
}请各位高手帮忙解决一下!!
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:abc/xml/spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
如果将上面内容中的<context-param>...</context-param>这个去掉JBOSS5启动时会提示找不到applicationContext.xml,加上则没事,由此是不是可以说加上这段内容applicationContext.xml已被加载,如果已被加载可为什么在用getBean获取bean时却提示找不到这个bean定义了一个servlet,在这个servlet的init()中获取bean
public void init(){
//getBean("bean名称");
//提示找不到这个bean
}请各位高手帮忙解决一下!!
bean名称要取<bean id="beanID" />中的id名称,及beanID
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
ctx.getBean("beanID");
怎么办啊?
我用的是JBOSS5 spring3 hibernate3 不知道是不是和这些有关系是不是JBOSS5对applicationContext位置有要求,必须要放在WEB-INF下
<param-name>contextConfigLocation</param-name>
<param-value>classpath:abc/xml/spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>这是在web.xml中的定义,如果将这些去掉,在启动JBOSS时会提示必须要添加
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
如果将<context-param>...</context-param>去掉则提示找不到applicationContext.xml
都试过了,一直提示找不到bean,真怪了!!!!
各位帮忙看下,用的是JBOSS5顺便说下,<param-value>classpath:abc/xml/spring/applicationContext-*.xml </param-value>这个配置在JBOSS4下直接就出现Could not resolve placeholder 'org.hibernate.cache.EhCacheProvider'这个错误
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
applicationContext.xml文件一般放在WEB-INF目录下
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
换成
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>我以前出现这个问题,改了这个就好了
在Jboss 5 CR2下写成classpath:abc/cde/applicationContext.xml虽然不报错,但根据BEAN名得不到BEAN,不知道是不是不支持这种写法还是需要在代码中动态中加载XML文件关于Could not resolve placeholder 'org.hibernate.cache.EhCacheProvider'这个错误是在配置缓存时一个类名写错了谢谢各位
JBOSS5,不支持通配符*,
写法要改成: <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
<!-- JBOSS5不支持通配符*.XML的写法,需要写成下面那样 rocklee@20110610 -->
classpath*:/spring/applicationContext.xml
classpath*:/spring/applicationContext-aop.xml
classpath*:/spring/applicationContext-dao.xml
classpath*:/spring/applicationContext-service.xml
</param-value>
</context-param>上面的写法试过可行,折腾我几天了!