Announcement Announcement Module
Collapse
No announcement yet.
BeanCreationException when creating a context after closing a context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanCreationException when creating a context after closing a context

    Whenever I create a ClassPathXmlApplicationContext and then later close it using the close() method, and then create a new ClasspathApplicationContext using the same or another XML configuration file, I get the following error:

    Code:
    java.util.concurrent.ExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.config.internalBeanConfigurerAspect': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.aspects.config.Neo4jAspectConfiguration#0': Cannot resolve reference to bean 'graphDbService' while setting bean property 'graphDatabaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'maintainer' defined in class path resource [engineContext.xml]: Cannot resolve reference to bean 'dbPath' while setting bean property 'db'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbPath' defined in class path resource [hpcServiceContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'neo4jTransactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
    I know very little about Spring and such, I am using a custom-made library that uses it. I've scoured the internet and have tried some things but I can't figure out what is causing this. It's definitely possible there is something about Spring that I do not understand and as such am using wrong, but it seems odd that a context influences another context, but only does so after it is closed. Also, the unresolvable circular reference error seems out of place, as it does not occur with contexts that are created before any context has been closed.

    The XMLs look like:

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
      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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">
    
      <context:annotation-config/>
      <context:spring-configured/>
      <aop:aspectj-autoproxy />
        
      <context:component-scan base-package="agentspring"/>
      <context:component-scan base-package="agentspring.simulation"/>
      <context:component-scan base-package="agentspring.lod"/>
    
      <bean id="maintainer" class="agentspring.graphdb.DbMaintainer" init-method="cleanup">
        <property name="db" ref="dbPath"/>
      </bean>
         
      <bean id="graphDbService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown" depends-on="maintainer">
        <constructor-arg index="0" ref="dbPath" />
        <constructor-arg index="1">
           <map>
            <entry key="neostore.nodestore.db.mapped_memory" value="90M"/>
            <entry key="neostore.relationshipstore.db.mapped_memory" value="1000M"/>
            <entry key="neostore.propertystore.db.mapped_memory" value="100M"/>
            <entry key="neostore.propertystore.db.strings.mapped_memory" value="100M"/>
            <entry key="neostore.propertystore.db.arrays.mapped_memory" value="0M"/>
          </map>
        </constructor-arg>
      </bean>
    
      <bean id="persistingBeanPostProcessor" class="agentspring.graphdb.PersistingBeanPostProcessor"/> 
    
      <neo4j:config graphDatabaseService="graphDbService"/>
      
      <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
        
      <bean id="executionInspector" class="agentspring.util.ExecutionInspector"/>
    
    </beans>
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
        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/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">  
      
    	<neo4j:repositories base-package="maasvlakte2.abm.repository"/>
      
    	<context:component-scan base-package="maasvlakte2.abm.role"/>
    
    	<bean id="engineService" class="agentspring.service.EngineServiceImpl"/>
    		<bean id="dbService" class="agentspring.service.DbServiceImpl">
    		<property name="filters" ref="dbFilters"/>
    	</bean>
    	
    	<bean id="dbPath" class="java.lang.String">
    	    <constructor-arg type="java.lang.String" value="${databasePath}" />
    	</bean>
    	
    	<bean class="agentspring.graphdb.NodeEntityHelper">
    		<property name="prefix" value="maasvlakte2.abm.domain"/>
    	</bean>
    	
    	<bean id="dbFilters" class="agentspring.graphdb.DefaultFiltersImpl"/>
    
    </beans>
    I'm kinda at the end of my rope here, so if anyone has any ideas I'd be very grateful.

  • #2
    Well I strongly suggest the reference guide as a starting point..

    For starters I would strongly suggest to remove the dbPath bean (why on earth is that a bean in the first case).

    Second your component-scan scans twice for the same beans the first already scans everything.
    Third, context:annotation-config is implied by component-scan.

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:util="http://www.springframework.org/schema/util"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
      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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">
    
      <context:annotation-config/>
      <context:spring-configured/>
      <aop:aspectj-autoproxy />
        
      <context:component-scan base-package="agentspring"/>
      <context:component-scan base-package="agentspring.simulation"/>
      <context:component-scan base-package="agentspring.lod"/>
    
      <bean id="maintainer" class="agentspring.graphdb.DbMaintainer" init-method="cleanup">
        <property name="db" value="${databasePath}"/>
      </bean>
         
      <bean id="graphDbService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown" depends-on="maintainer">
        <constructor-arg index="0" value="${databasePath}" />
        <constructor-arg index="1">
           <map>
            <entry key="neostore.nodestore.db.mapped_memory" value="90M"/>
            <entry key="neostore.relationshipstore.db.mapped_memory" value="1000M"/>
            <entry key="neostore.propertystore.db.mapped_memory" value="100M"/>
            <entry key="neostore.propertystore.db.strings.mapped_memory" value="100M"/>
            <entry key="neostore.propertystore.db.arrays.mapped_memory" value="0M"/>
          </map>
        </constructor-arg>
      </bean>
    
      <bean id="persistingBeanPostProcessor" class="agentspring.graphdb.PersistingBeanPostProcessor"/> 
    
      <neo4j:config graphDatabaseService="graphDbService"/>
      
      <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
        
      <bean id="executionInspector" class="agentspring.util.ExecutionInspector"/>
    Also why are you closing and recreating an applicationcontent, that is IMHO already a flaw in your process that is something you shouldn't be doing...

    Comment


    • #3
      Thank you for your comments.

      It turns out Neo4J cannot be reinitialized after a call to the shutdown method.

      Comment

      Working...
      X