最近在用sbt开发springmvc应用,其实主要是为了能用scala,由于对spring还不是很熟,资料里都是用Java写的,因此暂时倒尚未用scala写。今天配置aop,大概代码以下: java
@Around(value = "execution(* get(..)) && args(bookId, session) && @annotation(m)") public Object doGetBook(ProceedingJoinPoint pjp, long bookId, HttpSession session, MonitorPerformance m) throws Throwable {}
@RequestMapping(value = "/1", method = RequestMethod.GET) @ResponseBody @MonitorPerformance(2) public String get(@RequestParam(value = "bookId", required = false) long bookId, HttpSession session) {}
不过container:restart的时候老是报异常: spring
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'config': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer$AmbiguousBindingException: Found 2 candidate variable names but only one candidate binding slot when matching primitive args at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:471) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'config': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer$AmbiguousBindingException: Still 2 unbound args at this(),target(),args() binding stage, with no way to determine between them at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:471) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
javacOptions ++= Seq("-g")
@Around(value = "execution(* get(..)) && args(bookId, session) && @annotation(m)", argNames="pjp, bookId, session, m") public Object doGetBook(ProceedingJoinPoint pjp, Long bookId, HttpSession session, MonitorPerformance m) throws Throwable {}
这样就能够把sbt里javaOptions去掉!而后访问的时候又异常! session
nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.Long], and no parameter name information found in class file either
@RequestMapping(value = "/1", method = RequestMethod.GET) @ResponseBody @MonitorPerformance(2) public String get(@RequestParam(value = "bookId", required = false) Long bookId, HttpSession session) {}
required默认为true,不修改的话,不带参数会报错的,为了测试简单我修改成false。 mvc
总结就是配置的时候尽可能全面,不要依赖编译时候会有debug信息。由于method的参数,若是没有保留debug信息,是不知道名字的。对于class类型的话,到能够经过Class信息判断,可是对于primitive以及对于的wrapper类,还有String,都是不行的。 app