背景
我尝试在我的Spring应用程序中使用LightAdmin。我的根本问题是,它只支持一些基本的普通类型--例如,我使用了不支持的java.util.UUID (请看这里)。
由于这些都是静态方法,而且实际上没有任何POI来绑定自己的类型,所以我考虑使用方面进行绑定。
问题所在
但这又引起了另一个问题-我不能让我的方面劫持这个静态电话。LightAdmin作为一个单独的servlet工作,但是在同一个应用程序中,我的方面在applicationContext.xml中加载。
TypeHandler.java (方面代码):
@Aspect
public class TypeHandler
{
@Before("execution(static * org.lightadmin.core.persistence.metamodel.DomainTypeAttributeType.forType(..))")
public void myBefore()
{
System.out.println("HIJACKED!");
}
}applicationContext.xml片段:
<aop:aspectj-autoproxy/>
<context:component-scan
base-package="my.website.web.backend"
use-default-filters="true"
>
<context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
</context:component-scan>
<context:load-time-weaver/>我将Tomcat7与org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader类加载器结合使用。
在日志中我可以看到:
...
11:02:55.198 [localhost-startStop-1] INFO org.springframework.context.weaving.DefaultContextLoadTimeWeaver - Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
...
INFO: Initializing Spring FrameworkServlet 'backend'
11:03:11.677 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'backend': initialization started
11:03:11.687 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'backend-servlet': startup date [Fri Aug 08 11:03:11 CEST 2014]; parent: Root WebApplicationContext
11:03:11.689 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/backend-servlet.xml]
11:03:11.770 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'backend': initialization completed in 93 ms
sie 08, 2014 11:03:11 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'lightadmin-dispatcher'
11:03:11.772 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'lightadmin-dispatcher': initialization started
11:03:11.773 [localhost-startStop-1] INFO org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Refreshing WebApplicationContext for namespace 'lightadmin-dispatcher-servlet': startup date [Fri Aug 08 11:03:11 CEST 2014]; parent: Root WebApplicationContext
...(/WEB-INF/backend-servlet.xml为空)
在为我的UUID字段调用org.lightadmin.core.persistence.metamodel.DomainTypeAttributeType.forType()之后,应用程序就会失败,而不会被方面劫持。
我已经尝试过添加@Component注释,在applicationContext.xml中手动注册bean等等-没有效果。我认为方面本身是由beans工厂加载的,因为如果配置无效的切入点,就会有例外。
问题
所以我的两个问题是:
发布于 2014-09-04 12:02:47
请使用最新重新设计的LightAdmin版本和一组支持的扩展类型(UUID,Joda-Time)。它被升级到Spring4.0.X,这是最新的Spring数据/REST,并包含了一系列缺陷修复。
顺便说一句,您不再需要在发布时使用LightAdmin Nexus存储库了。它现在可以直接从Maven Central获得。
发布于 2014-08-20 12:16:43
Spring不能用于静态方法。为此,您必须使用完整的AspecJ。您可以在如何在Spring中拦截静态方法?中找到另一个引用。
定义切入点时也没有例外,因为它的语法在AspectJ中是有效的,只是Spring不能处理它。
https://stackoverflow.com/questions/25200112
复制相似问题