0

How to do component-scan in spring 3.0? I use annotation like @Service, @Reponsity for both jar and project. It does not work. When the bean in project inject from the bean in jar.

In jar file

    com.java.spring.support

In project

    org.me.project

My configuration is

    <context:annotation-config/>
    <context:component-scan base-package="com.java.spring.support, org.me.project"/>

In Jar File

    package com.java.spring.support;

    @Service("CommonService")
    public class CommonService {
    }

In project

    package org.me.project;

    @Service(value = "OtherService")
    public class OtherService {
        @Resource(name = "CommonService")
        private CommonService service;
    }

I get error

    15:41:53,043 DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.sprin
    gframework.context.support.DefaultLifecycleProcessor@510ebe18]
    15:41:53,044 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Returning cached instance of singleton bean 'lifecycleProcessor'
    Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'CommonService' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
        at org.ace.java.support.delete.Test.main(Test.java:13)
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131

2 Answers2

0

Use only <context:component-scan base-package="com.java.spring.support, org.me.project"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> should work.

Mukesh Kumar
  • 945
  • 4
  • 11
  • 26
0
<context:component-scan base-package="org.me.project"/> 

You are using an exclude filter on repository annotations, remove it.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • @CycDemo thats how you specify annotation based config; what exactly is the error you are getting ? – NimChimpsky Sep 26 '12 at 09:07
  • @CycDemo ok, show the declaration of bean named 'CodecHandler'. And why are using a main method in delete.Test ? Show the code for that too – NimChimpsky Sep 26 '12 at 09:14
  • @CycDemo you have not shown the code that is causing the error. That is test.Main and CodecHandler;also bean id should start with lowercase, the java camelCase convention. – NimChimpsky Sep 26 '12 at 09:19
  • I already change `CodecHandler` to `CommonService`. Actually it is actually happen. – Zaw Than oo Sep 26 '12 at 09:21