Results 1 to 4 of 4

Thread: Problem with AOP,@component,@Resource

  1. #1
    Join Date
    Nov 2010
    Posts
    3

    Default Problem with AOP,@component,@Resource

    HI,
    my problem is as follows :
    I want to use annotition in my project,but it does not work with AOP,

    The code :
    //
    public interface Dao {

    public void test();
    }
    //
    @Component("dao")
    public class DaoImpl implements Dao {
    public void test() {
    System.out.println("just a test");
    }
    }
    //
    @Aspect
    public class TestIntercepor {

    @Pointcut("execution(* com.pkg.dao.impl.*.*(..))")
    public void allDaoIMpl(){};
    @Before("allDaoIMpl()")
    public void check(JoinPoint jp){
    System.out.println(jp.getTarget().getClass().getNa me());
    }
    }

    @Controller
    public class UserController {
    @Resource(name = "dao")
    private Dao dao;

    @RequestMapping("test")
    public String areaList(Model model){
    dao.test();
    return "";
    }
    }


    when I use @component("dao") on the implemention class ,the aop does not
    work,but if I define <bean id="dao" class="com.pkg.dao.impl.DaoImpl"/> in the xml file ,it works well.

    Help me please,many thanks!
    Last edited by moony; Nov 16th, 2010 at 03:17 AM. Reason: for some errors

  2. #2
    Join Date
    Nov 2010
    Posts
    1

    Default

    Spring isn't finding your Dao component when it scans for them. Check out:

    http://forum.springsource.org/showthread.php?t=49182

  3. #3
    Join Date
    Nov 2010
    Posts
    3

    Default to brunkb

    Quote Originally Posted by brunkb View Post
    Spring isn't finding your Dao component when it scans for them. Check out:

    http://forum.springsource.org/showthread.php?t=49182

    uh-huh, you are right ,"Spring isn't finding my Dao component".
    I should have put
    <context:component-scan base-package="com.pkg">
    <context:include-filter type="aspectj" expression="com.pkg..*"/>
    </context:component-scan>
    <aop:aspectj-autoproxy/>
    in the same xml file
    whlie
    I put
    <context:component-scan base-package="com.pkg">
    <context:include-filter type="aspectj" expression="com.pkg..*"/>
    </context:component-scan>
    in the dispatcher-servlet.xml and
    <aop:aspectj-autoproxy/>
    in the applicationContext.xml.

    many thanks!
    Last edited by moony; Nov 16th, 2010 at 09:09 PM. Reason: some errors

  4. #4
    Join Date
    Nov 2010
    Posts
    3

    Default

    Quote Originally Posted by brunkb View Post
    Spring isn't finding your Dao component when it scans for them. Check out:

    http://forum.springsource.org/showthread.php?t=49182
    many thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •