Announcement Announcement Module
Collapse
No announcement yet.
Moving Spring 2.0.4 attribute singleton problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving Spring 2.0.4 attribute singleton problem

    I'm upgrading to Spring 2.0.4, i have changed the jars.
    I have define beans in applicationContext-services.xml file like this

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "/tld/spring-beans-2.0.dtd">
    <beans>
    <bean name="serviceFactoryImpl" class="com.vopium.services.ServiceFactoryImpl" singleton="true">
    <property name="baseApplicationCacheInterface"
    ref="applicationCacheServiceImpl">
    </property>
    </bean>

    But it is giving me the following exception

    ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
    org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 5 in XML document from ServletContext resource [/WEB-INF/applicationContext-services.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "singleton" must be declared for element type "bean".
    Caused by:
    org.xml.sax.SAXParseException: Attribute "singleton" must be declared for element type "bean".
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:236)

    I'm just stuck here as i have added the attribute "singleton" in every element type "bean" but still getting this error

    Please help me in this problem
    Thanks in advance

    Mazhar Shaukat

  • #2
    Originally posted by mazhar View Post
    <bean name="serviceFactoryImpl" class="com.vopium.services.ServiceFactoryImpl" singleton="true">
    Try this:

    Code:
    <bean name="serviceFactoryImpl" class="com.vopium.services.ServiceFactoryImpl" scope="singleton">
    or omit it altogether, as singleton is the default.

    BTW: Your doctype declaration seems odd. Please try this one:
    Code:
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
    		  "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
    Regards,
    Andreas

    P.S.: Please use [ code] [ /code] tags

    Comment


    • #3
      Just to add to the point Andreas made, the reference manual has some information on this.
      If you are referencing the 'spring-beans.dtd' DTD in a bean definition file(s), and you are being explicit about the lifecycle scope of your bean(s) you must use the "singleton" attribute to express the lifecycle scope (remembering that the singleton lifecycle scope is the default). If you are referencing the 'spring-beans-2.0.dtd' DTD or the Spring 2.0 XSD schema, then you will need to use the "scope" attribute (because the "singleton" attribute was removed from the definition of the new DTD and XSD files in favour of the "scope" attribute).

      To be totally clear about this, this means that if you use the "singleton" attribute in an XML bean definition then you must be referencing the 'spring-beans.dtd' DTD in that file. If you are using the "scope" attribute then you must be referencing either the 'spring-beans-2.0.dtd' DTD or the 'spring-beans-2.0.xsd' XSD in that file.
      http://www.springframework.org/docs/...factory-scopes

      Comment


      • #4
        Thnx a lot both of you
        now i'm not getting that error, but now it is saying that

        2007-05-04 11:29:52,537 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultL [email protected]: defining beans [serviceFactoryImpl,gatewayXMLUtil,countryGatewayXM LUtil,applicationCacheServiceImpl,messagesServiceI mpl,gatewayMessageServiceImpl,gatewayServiceImpl,m essageUserAgentAppServiceImpl,messageGatewayServic eImpl,priceCodeServiceImpl,countryGatewayServiceIm pl,callDetailRecordServiceImpl,userServiceImpl,sms ServiceImpl,vopiumServiceImpl,callbackServiceImpl, serveWapPushReceiveServiceImpl,gatewayFactory,serv eSMSRequestService,serveSMSRequestOperaService,xml Reader,validationService,baseGatewayImpl,unwire,op era,country,RouteCountries,language,allCountries,a llLanguages,commonServiceImpl,friendMailSender,mai lSender,securityInterceptor,userProfileGeneralServ iceImpl,userProfileInterestServiceImpl,userProfile ContactServiceImpl,userProfileProfessionalServiceI mpl,userProfilePersonalServiceImpl,Features,Build, Children,Dating,Degree,Drinking,Education,Ethnicit y,Eyes,Hairs,Industry,Looks,Pets,PoliticalViews,Re lationship,Religion,SexualOrientation,Smoking,SubI ndustry,News,cardBlockServiceImpl,prepaidCardsServ iceImpl,communityServiceImpl,weeklyTrigger,weeklyJ obDetail,vopiumUserLowBalanceScheduler,vopiumSMSTh read,autoTopupThread,vopiumTellAFriendSMSThread,ra tesXmlUtility,dataSource,sessionFactory,portalHibe rnateProperties,feedBackJdbcDAO,cdrJdbcDAO,cardsDA O,applicationUserDAO,supportedSetsJdbcDAO,missingC ellsJdbcDAO,downloadApplicationJdbcDAO,paymentLogJ dbcDAO,applicationUsersJdbcDAO,cardsJdbcDAO,callDe tailRecordJdbcDAO,baseDAO,baseJdbcDAO,baseServiceI mpl,baseFormAction,baseController,baseFormControll er,baseValidator,baseSecurityInterceptor,viewResol ver,messageSource,baseExceptionHandler,localeChang eInterceptor,localeResolver,multipartResolver,base DefaultMessageCodesResolver,clipBoardUtility]; root of factory hierarchy
        2007-05-04 11:29:52,552 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'serviceFactoryImpl' defined in ServletContext resource [/WEB-INF/applicationContext-services.xml]: Cannot resolve reference to bean 'applicationCacheServiceImpl' while setting bean property 'baseApplicationCacheInterface'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'applicationCacheServiceImpl' defined in ServletContext resource [/WEB-INF/applicationContext-services.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
        Caused by:
        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'applicationCacheServiceImpl' defined in ServletContext resource [/WEB-INF/applicationContext-services.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
        Caused by:
        java.lang.NullPointerException
        at com.vopium.services.ApplicationCacheServiceImpl.af terPropertiesSet(ApplicationCacheServiceImpl.java: 67)

        But it is working fine with the previous version of Spring
        i don't know wat's the problem now

        Comment


        • #5
          Originally posted by mazhar View Post
          Caused by:
          java.lang.NullPointerException
          at com.vopium.services.ApplicationCacheServiceImpl.af terPropertiesSet(ApplicationCacheServiceImpl.java: 67)

          But it is working fine with the previous version of Spring
          i don't know wat's the problem now
          But we can't neither since it's your code. Just have a look on line 67 of ApplicationCacheServiceImpl and see what can be null there.

          Jörg

          Comment


          • #6
            According to your log, the problem is a NullPointerException in line 67 of ApplicationCacheServiceImpl (method afterPropertiesSet).
            Have a look what happens there. If in doubt, just post the code of that method (marking line 67).

            Regards,
            Andreas

            Comment


            • #7
              singleton problem in migrating to spring2.0

              While doing the migration of project from spring 1.2.6 to spring 2.0
              I was encountered with the following exception....

              ----------------------------------------------------------------------------------------------------------------------------------------------------------------
              "[1/5/09 17:01:16:725 IST] 0000004f SystemOut O 17:01:16.725 - et.DispatcherServlet - Context initialization failed
              org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eiwo-errorqueue.controller' defined in class path resource [eiwo-context.xml]: Cannot resolve reference to bean 'eiwoerrorq.validator' while setting bean property 'validator'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eiwoerrorq.validator' defined in class path resource [eiwo-context.xml]: Cannot resolve reference to bean 'eiwoerrorqueue.commandTemplate' while setting bean property 'commandTemplate'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eiwoerrorqueue.commandTemplate' defined in class path resource [eiwo-context.xml]: Cannot create inner bean 'eiwoerrorqueue.reportFiter' while setting bean property 'reportFilter'; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Inner bean definition 'eiwoerrorqueue.reportFiter' for bean property 'reportFilter' has scope 'singleton' but containing bean definition 'eiwoerrorqueue.commandTemplate' does not. Mark the inner bean definition with scope 'prototype' instead.
              Caused by:
              org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eiwoerrorq.validator' defined in class path resource [eiwo-context.xml]: Cannot resolve reference to bean 'eiwoerrorqueue.commandTemplate' while setting bean property 'commandTemplate'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eiwoerrorqueue.commandTemplate' defined in class path resource [eiwo-context.xml]: Cannot create inner bean 'eiwoerrorqueue.reportFiter' while setting bean property 'reportFilter'; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Inner bean definition 'eiwoerrorqueue.reportFiter' for bean property 'reportFilter' has scope 'singleton' but containing bean definition 'eiwoerrorqueue.commandTemplate' does not. Mark the inner bean definition with scope 'prototype' instead.
              Caused by:
              org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eiwoerrorqueue.commandTemplate' defined in class path resource [eiwo-context.xml]: Cannot create inner bean 'eiwoerrorqueue.reportFiter' while setting bean property 'reportFilter'; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Inner bean definition 'eiwoerrorqueue.reportFiter' for bean property 'reportFilter' has scope 'singleton' but containing bean definition 'eiwoerrorqueue.commandTemplate' does not. Mark the inner bean definition with scope 'prototype' instead.
              Caused by:
              org.springframework.beans.factory.BeanDefinitionSt oreException: Inner bean definition 'eiwoerrorqueue.reportFiter' for bean property 'reportFilter' has scope 'singleton' but containing bean definition 'eiwoerrorqueue.commandTemplate' does not. Mark the inner bean definition with scope 'prototype' instead.
              "
              --------------------------------------------------------------------------

              In the bold block it is saying to change the inner bean type to prototype Where as it is working properly when we use sprig-1.2.6.jar.

              Plz tell me is there any alternate solution?
              what will be effect if you change the singleton to prototype?


              Thanks,
              Badineni
              Last edited by badineni; Jan 6th, 2009, 12:29 AM. Reason: text change

              Comment


              • #8
                Hi Badineni,

                Looking at the error, it seems that you have made a mistake in your migration.

                Where you had <bean singleton="false"> you could now have <bean ... scope="prototype">

                and where you had <bean singleton="true"> or just <bean > (i.e. the default is singleton), then you don't need to specify the scope as it defaults to singleton.

                Did you really have a Singleton referenced from a Prototype before?

                Cheers,

                Neale

                Comment


                • #9
                  Hi,

                  Things that might help you regarding Inner beans -->

                  1. Inner beans are always anonymous
                  2. The 'scope' flag and any 'id' or 'name' attribute are effectively ignored.

                  Thanks,
                  Sreeram

                  Comment


                  • #10
                    Moving Spring 2.0.4 attribute singleton problem

                    Hi neale and sreeram,

                    Thanks for the reply.
                    scopes and tags are correct only.
                    I have browsed through the bugs in spring2.0

                    That is a bug in spring2.0 and the same is resolved in subsequent releases.
                    so those who wants to use upgrade to spring2.0 should go for spring-2.0.8.

                    please go through the following link.
                    http://jira.springframework.org/browse/SPR-2744

                    problem is solved.

                    Thanks,
                    Badineni

                    Comment

                    Working...
                    X