JBoss Seam -Spring集成中的应用程序上下文错误

时间:2010-11-26 06:26:26

标签: spring jboss seam

  • 我想知道如果我所做的所有配置都是正确的?如果您需要任何配置文件,请索取。谢谢。我是这类问题的新手。 :)

嗨,我遇到的问题是这样的:当Spring bean初始化并开始向其中注入seam组件时,但是在服务器启动期间,seam组件不存在,我得到了 java.lang .IllegalStateException:没有活动的应用程序上下文

错误日志和配置如下:

错误日志:

13:35:34,698 ERROR [DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name     'springController' defined in ServletContext resource [/WEB-INF/NUSLibraries-servlet.xml]:     Cannot resolve reference to bean 'ActionPortalStaticPage' while setting bean property     'portalStaticPage'; nested exception is     org.springframework.beans.factory.BeanCreationException: Error creating bean with name     'ActionPortalStaticPage': FactoryBean threw exception on object creation; nested exception     is java.lang.IllegalStateException: No application context active
    at     org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanD    efinitionValueResolver.java:328)
    at     org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessar    y(BeanDefinitionValueResolver.java:106)
    at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyVa    lues(AbstractAutowireCapableBeanFactory.java:1325)
at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Ab    stractAutowireCapableBeanFactory.java:1086)
    at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Ab    stractAutowireCapableBeanFactory.java:517)
        at                 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abst    ractAutowireCapableBeanFactory.java:456)
    at     org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactor    y.java:291)
            at     org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultS    ingletonBeanRegistry.java:222)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.    java:288)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.ja    va:190)
    at     org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton        s(DefaultListableBeanFactory.java:580)
    at     org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitializati        on(AbstractApplicationContext.java:895)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean     with name 'ActionPortalStaticPage': FactoryBean threw exception on object creation; nested     exception is java.lang.IllegalStateException: No application context active
    at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryB    ean(FactoryBeanRegistrySupport.java:149)
        at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBea    n(FactoryBeanRegistrySupport.java:109)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(Abstr    actBeanFactory.java:1429)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.    java:302)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.ja    va:190)
    at     org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanD    efinitionValueResolver.java:322)
    ... 89 more
Caused by: java.lang.IllegalStateException: No application context active
    at org.jboss.seam.Component.forName(Component.java:1945)
    at org.jboss.seam.Component.getInstance(Component.java:2005)
    at org.jboss.seam.Component.getInstance(Component.java:1983)
    at org.jboss.seam.Component.getInstance(Component.java:1977)
    at org.jboss.seam.Component.getInstance(Component.java:1972)
    at org.jboss.seam.ioc.spring.SeamTargetSource.getTarget(SeamTargetSource.java:85)
    at org.jboss.seam.ioc.spring.SeamFactoryBean.createInstance(SeamFactoryBean.java:97)
    at     org.springframework.beans.factory.config.AbstractFactoryBean.getObject(AbstractFactoryBean.j    ava:146)
    at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryB    ean(FactoryBeanRegistrySupport.java:142)
    ... 94 more
13:35:34,714 ERROR [[/frontend]] StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name     'springController' defined in ServletContext resource [/WEB-INF/NUSLibraries-servlet.xml]:     Cannot resolve reference to bean 'ActionPortalStaticPage' while setting bean property     'portalStaticPage'; nested exception is     org.springframework.beans.factory.BeanCreationException: Error creating bean with name         'ActionPortalStaticPage': FactoryBean threw exception on object creation; nested exception     is java.lang.IllegalStateException: No application context active
    at         org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanD    efinitionValueResolver.java:328)
    at     org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessar    y(BeanDefinitionValueResolver.java:106)
        at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyVa        lues(AbstractAutowireCapableBeanFactory.java:1325)
    at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Ab    stractAutowireCapableBeanFactory.java:1086)
    at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Ab    stractAutowireCapableBeanFactory.java:517)
    at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abst    ractAutowireCapableBeanFactory.java:456)
    at     org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactor    y.java:291)
    at         org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultS    ingletonBeanRegistry.java:222)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.    java:288)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.ja    va:190)
    at         org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton    s(DefaultListableBeanFactory.java:580)
    at     org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitializati    on(AbstractApplicationContext.java:895)
    at     org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationCo        ntext.java:425)
    at     org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServle        t.java:442)
    at     org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServle    t.java:458)
    at     org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.    java:339)
    at     org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
        at     org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:950)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4122)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4421)
            at     org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployme    nt.java:310)
    at         org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:            142)
    at     org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
    at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
    at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at     org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAd        apter.java:117)
    at     org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployA                ction.java:70)
    at             org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProf    ileAction.java:53)
    at     org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractPro    fileService.java:403)
                at     org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.jav    a:348)
    at     org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1633)
    at             org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:935)
        at     org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1083    )
    at         org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:985)
    at     org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:775)
    at         org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
    at     org.jboss.system.server.profileservice.repository.AbstractProfileService.registerProfile(Abs    tractProfileService.java:308)
    at     org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap    .java:256)
    at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
    at org.jboss.Main.boot(Main.java:221)
    at org.jboss.Main$1.run(Main.java:556)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean     with name 'ActionPortalStaticPage': FactoryBean threw exception on object creation; nested     exception is java.lang.IllegalStateException: No application context active
    at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryB    ean(FactoryBeanRegistrySupport.java:149)
    at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBea                n(FactoryBeanRegistrySupport.java:109)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(Abstr    actBeanFactory.java:1429)
                at     org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.                java:302)
    at     org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.ja    va:190)
        at     org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanD                efinitionValueResolver.java:322)
    ... 89 more
Caused by: java.lang.IllegalStateException: No application context active
    at org.jboss.seam.Component.forName(Component.java:1945)
    at org.jboss.seam.Component.getInstance(Component.java:2005)
    at org.jboss.seam.Component.getInstance(Component.java:1983)
    at org.jboss.seam.Component.getInstance(Component.java:1977)
at org.jboss.seam.Component.getInstance(Component.java:1972)
    at org.jboss.seam.ioc.spring.SeamTargetSource.getTarget(SeamTargetSource.java:85)
    at org.jboss.seam.ioc.spring.SeamFactoryBean.createInstance(SeamFactoryBean.java:97)
    at     org.springframework.beans.factory.config.AbstractFactoryBean.getObject(AbstractFactoryBean.j    ava:146)
    at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryB    ean(FactoryBeanRegistrySupport.java:142)
    ... 94 more
13:35:34,714 ERROR [[/frontend]] Servlet /frontend threw load() exception
java.lang.IllegalStateException: No application context active
    at org.jboss.seam.Component.forName(Component.java:1945)
        at org.jboss.seam.Component.getInstance(Component.java:2005)
    at org.jboss.seam.Component.getInstance(Component.java:1983)
    at org.jboss.seam.Component.getInstance(Component.java:1977)
    at org.jboss.seam.Component.getInstance(Component.java:1972)
    at org.jboss.seam.ioc.spring.SeamTargetSource.getTarget(SeamTargetSource.java:85)
    at org.jboss.seam.ioc.spring.SeamFactoryBean.createInstance(SeamFactoryBean.java:97)
    at     org.springframework.beans.factory.config.AbstractFactoryBean.getObject(AbstractFactoryBean.j    ava:146)
    at     org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryB    ean

我的Web.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>frontend</display-name>
<welcome-file-list>
  <welcome-file>index.xhtml</welcome-file>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.html</welcome-file>
  <welcome-file>default.htm</welcome-file>
  <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.seam</url-pattern>
</servlet-mapping>
<context-param>
  <param-name>org.richfaces.SKIN</param-name>
  <param-value>blueSky</param-value>
</context-param>
<listener>
  <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
  <filter-name>Seam Filter</filter-name>
  <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>Seam Filter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
  <servlet-name>Seam Resource Servlet</servlet-name>
  <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>Seam Resource Servlet</servlet-name>
  <url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<context-param>
  <param-name>facelets.DEVELOPMENT</param-name>
  <param-value>true</param-value>
</context-param>
<context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
</context-param>
<security-constraint>
  <display-name>Restrict raw XHTML Documents</display-name>
  <web-resource-collection>
    <web-resource-name>XHTML</web-resource-name>
    <url-pattern>*.xhtml</url-pattern>
  </web-resource-collection>
  <auth-constraint/>
</security-constraint>

<servlet>
<servlet-name>NUSLibraries</servlet-name>
<servlet-class>
 org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
 <servlet-name>NUSLibraries</servlet-name>
 <url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>

我的application-context.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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p" 
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:seam="http://jboss.com/products/seam/spring"
    xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-    3.0.xsd
                   http://www.springframework.org/schema/context
                   http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                           http://jboss.com/products/seam/spring-seam
                           http://jboss.com/products/seam/spring-seam-2.1.xsd">

 <bean id="viewResolver"     class="org.springframework.web.servlet.view.InternalResourceViewResolver" > 
  <property name="suffix">  
   <value>.xhtml</value>  
  </property> 
 </bean>

  <!-- Controller -->
  <bean id="springController" class="org.domain.frontend.controller.SpringController">
    <property name="portalStaticPage" ref="ActionPortalStaticPage">
    </property>
  </bean>

  <seam:instance name="ActionPortalStaticPage" id="ActionPortalStaticPage"/>  

  <bean id="handlerMapping"     class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <value>
                /*/*=springController
            </value>
        </property>
  </bean>

</beans>

我的控制器:

package org.domain.frontend.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;

import javax.persistence.NoResultException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.domain.frontend.session.ActionPortalStaticPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.RequestContextUtils;

@Controller
    @Transactional
public class SpringController{

 static Logger log = Logger.getLogger("SpringController");
 private ActionPortalStaticPage portalStaticPage; 

 public void setPortalStaticPage(ActionPortalStaticPage portalStaticPage) {
  this.portalStaticPage = portalStaticPage;
 }


 @RequestMapping("/*/{param}")
 public ModelAndView langzh(HttpServletRequest request, HttpServletResponse response,     @PathVariable("param") String param) throws Exception {

  List<String> params = new ArrayList<String>();
  try{
   log.info("param("+param+")");
   StringTokenizer st = new StringTokenizer(param,"-");
   while (st.hasMoreTokens()) {
    params.add(st.nextToken());
   }
   portalStaticPage.setTitle(params.toString());
   log.info("portalStaticPage("+portalStaticPage.getTitle()+")");
         return new ModelAndView("index");
  }    
      catch(Exception ex){
       ex.printStackTrace();
      return new ModelAndView(params.get(0));

  }         
 }
}

感谢每一个宝贵的评论!也许我没有以正确的方式做到这一点。 谢谢

1 个答案:

答案 0 :(得分:0)

我无法看到applicationContext的初始化位置。在春季网络应用程序中,我添加了

<listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

到加载web.xml的{​​{1}}。 我不确定是否推荐/需要使用接缝集成。