Announcement Announcement Module
Collapse
No announcement yet.
Problem with AOP,@component,@Resource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 04:17 AM. Reason: for some errors

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

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

    Comment


    • #3
      to brunkb

      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, 10:09 PM. Reason: some errors

      Comment


      • #4
        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!

        Comment

        Working...
        X