Results 1 to 7 of 7

Thread: expression="annotation(@Service)" poincut not well formed

  1. #1
    Join Date
    Sep 2004
    Posts
    602

    Default expression="annotation(@Service)" poincut not well formed

    What's wrong with this pointcut ? And is this the best way of making services transactional ?

    Code:
    <aop:config>
    		<aop:pointcut id="services"   expression="annotation(@Service)" />
    		<aop:advisor id="transactions" advice-ref="jpaTxAdvice"
    			pointcut-ref="services" />
    	</aop:config>
    If I remove the advisor, I get no XML errors, so it looks like the advisor doesn't like the format of my pointcut.


    Code:
    Pointcut is not well-formed: expecting 'name pattern' at character position 19
    annotation(@Service)
                       ^
    
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
    	at java.security.AccessController.doPrivileged(AccessController.java:193)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:400)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
    	at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:243)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:212)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:187)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
    	at junit.framework.TestCase.runBare(TestCase.java:125)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 19
    annotation(@Service)
                       ^
    
    	at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:333)
    	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:308)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:197)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:184)
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:165)
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:189)
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:244)
    	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:278)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:113)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:85)
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:296)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1266)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
    	... 30 more
    Last edited by Paul Newport; Feb 18th, 2008 at 03:59 AM. Reason: more info

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    If you want transactional stuff I would suggest the @Transactional annotation and the tx:annotation-driven element. It is especially for that purpose.

    Next to that you might want to try the fully qualified classname of the @Service annotation and the pointcut expression is @annotation not annotation.. (@org.springframework.stereotype.Service).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by mdeinum View Post
    If you want transactional stuff I would suggest the @Transactional annotation and the tx:annotation-driven element. It is especially for that purpose.

    Next to that you might want to try the fully qualified classname of the @Service annotation and the pointcut expression is @annotation not annotation.. (@org.springframework.stereotype.Service).

    OK, thanks for that. What's the point of the @service annotation then ? It doesn't seem to do much at all other than act as a possible place holder for pointcuts.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Check the chapter for component scanning and automatic component registering. Chapter 3.11 is the one to read. I suggest you readup on that stuff and what it is to be used for.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by mdeinum View Post
    Check the chapter for component scanning and automatic component registering. Chapter 3.11 is the one to read. I suggest you readup on that stuff and what it is to be used for.
    I understand component scanning but thought @service would do something more, like make the component transactional.

    I'm trying to understand whether it is better to annotate with @transactional or annotate with @service and then put in a pointcut to advise stuff annotated with @service (which perhaps is less verbose).

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    It is less verbose but also less powerfull... How would you differentiate between a method which required a new transaction or nested transaction when called. Or a method needs no transaction? If you do it with the @Service annotation everything is transactional with the same settings...

    @Service is for use with the component scanning and it also types your pojo (you could also annotate it with @Component for the same behavior but @Service makes clear it is a service like @Controller, @Repository etc. do for other types).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by mdeinum View Post
    It is less verbose but also less powerfull... How would you differentiate between a method which required a new transaction or nested transaction when called. Or a method needs no transaction? If you do it with the @Service annotation everything is transactional with the same settings...

    @Service is for use with the component scanning and it also types your pojo (you could also annotate it with @Component for the same behavior but @Service makes clear it is a service like @Controller, @Repository etc. do for other types).
    OK thanks, all clear now. As you can see I am at the bottom of the AOP annotations learning curve !

Posting Permissions

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