Announcement Announcement Module
No announcement yet.
load spring app context with annotations (standalone) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • load spring app context with annotations (standalone)


    I have a web application up and running with annotation based services/components. The web app runs fine.

    Now I am trying to load the same context in a standalone java application.
    ClassPathXmlApplicationContext ctx =
    new ClassPathXmlApplicationContext(new String[] {"spring/infrastructure-context.xml", "spring/services-context.xml"});
    the configuration is loaded with the error below
    No bean named 'groupDefinitionTagCreator' is defined

    This bean is annotated with @Service("groupDefinitionTagCreator") and not defined in the xml configuration files.

    How do I load my configuration that has annotated services.

    BTW: my configuration works fine when run as a web app.

    I tried to look for any other implementations of ApplicationContext some thing like AnnotationBasedApplicationContext but didnt find any.

    Can somebody guide me how to achieve this?

    // the following is the one that is failing to be initialized.

    <!-- Provides support for tagging audited entities -->
    <bean id="tagFactoryService" class="com.workscape.auditing.AuditTagFactoryImpl">
    	<property name="defaultTagCreator" ref="defaultTagCreator" />
    	<property name="tagCreatorMap">
    			<entry key="com.workscape.em.model.GroupDefinition"
     value-ref="groupDefinitionTagCreator" /> // this is referring to a annotate service @Service("groupDefinitionTagCreator")
    Last edited by smadarapu; Mar 22nd, 2010, 11:12 AM. Reason: Thought the message was not clear, refined the title.

  • #2
    Any body from the Spring developers, can you at least give some idea? Am I doing something completely wrong?
    Last edited by smadarapu; Mar 22nd, 2010, 03:14 PM.


    • #3
      From your previous Spring context configuration snippet, couldn't really make out if you have the annotation config (specifically the component scanning) turned ON.

      From the Spring reference documentation section on :Automatically detecting classes and registering bean definitions" ... you must have the following in your configuration. The AutowiredAnnotationBeanPostProcessor and CommonAnnotationBeanPostProcessor are both included implicitly when you use the component-scan element. That means that the two components are autodetected and wired together - all without any bean configuration metadata provided in XML.

      <context:component-scan base-package="org.example"/>


      • #4
        Yes i have the component-scan tag in my config file, i just posted part of my configuration (the problematic one). As I mentioned all the beans are correctly discovered when run inside the webserver. I am trying to load the same configuration from a standalone java app.