Announcement Announcement Module
Collapse
No announcement yet.
Advice parameters can not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advice parameters can not work

    the spring version is 3
    it's throw
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'parameter' defined in file [F:\ProProject\JSP\spring\WebRoot\WEB-INF\classes\com\spring\aop\service\Parameter.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut show

    xml file
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
    		http://www.springframework.org/schema/beans 
    		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/aop 
    		http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    		http://www.springframework.org/schema/tx
    		http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    	
    	<aop:aspectj-autoproxy/>
    	<context:component-scan base-package="com.spring.aop"/>
    
    </beans>
    aspect class
    Code:
    @Aspect
    @Component("notVeryUsefulAspect")
    public class NotVeryUsefulAspect {
    	  @Before("com.spring.aop.service.Parameter.show() && args(s,..)")
    	  public void needParameter(String s) {
    		  System.out.println("parameter is " + s);
    	  }
    
    }
    be aspect class
    Code:
    @Component("parameter")
    public class Parameter {
    
    	public void show(String s) {
    		System.out.println(s);
    	}
    }
    test class
    Code:
    	@Test
    	public void test2() {
    		Parameter p = context.getBean("parameter", Parameter.class);
    		p.show("nagisa");
    	}
    Last edited by sion; Nov 23rd, 2010, 07:27 PM.

  • #2
    Because your pointcut is wrong... You have a pointcut without parameters and try to bind the first parameter to the s param in your method. Which isn't going to work...

    Code:
    @Before("com.spring.aop.service.Parameter.show(*) && args(s)")
    It should be something like that...

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      Because your pointcut is wrong... You have a pointcut without parameters and try to bind the first parameter to the s param in your method. Which isn't going to work...

      Code:
      @Before("com.spring.aop.service.Parameter.show(*) && args(s)")
      It should be something like that...
      Thanks,but it is still not work - -!

      Comment


      • #4
        Well I do not hope you used the pointcut as is... Because that was also wrong...

        Code:
        @Before("* com.spring.aop.service.Parameter.show(*) && args(s))")
        If it doesn't work you also might want to show us what doesn't work instead of only stating that it doesn't work...

        Comment

        Working...
        X