0

我正在尝试这样做:我创建了一个抽象工厂,它为我提供了具体工厂。我使用具体工厂来创建对象。对象基本上是由具体工厂中的 new 关键字创建的。现在这个新创建的对象需要自动装配 bean,这些 bean 的范围是请求或会话,所以我在它们周围使用了范围代理。

我了解到可以使用 ASPECT J 对使用 new 关键字创建的对象进行自动装配。所以我尝试对其进行配置。我正在使用我的 eclipse 和内置的 tomcat 6 并且没有构建工具。

1.scoped 代理 bean 使用 cglib 配置并且运行良好。2.然后我创建了工厂来创建具体的对象。3.当我使用@configurable 注释时出现问题。

这是我的分步代码。

这是混凝土工厂

公共类 LoadEntityFactory 扩展 EntitiesAbstractFactory {

@Override
public loadEntities getLoadEntity(String entity) {
    if(entity==null){
        return null;
    }else if (entity.equalsIgnoreCase("categories")) {

        return new LoadCategoryEntity();
    }
    else if (entity.equalsIgnoreCase("books")) {
        return new LoadBookEntity();
    }

    return null;
}

}

这是我的类,由混凝土工厂创建,需要自动连接其他一些范围代理 Bean(在我的情况下是服务)

@Configurable
public class LoadCategoryEntity implements loadEntities {

    private InputStream iStream;
    private category_pojo categories;

    private Set<category_pojo> categorySet;

    public EntitiesLoadService categoryLoadService;





    @Autowired
    @Qualifier("categoryLoadService")
    public void setCategoryLoadService(EntitiesLoadService categoryLoadService) {
        this.categoryLoadService = categoryLoadService;
    }

这是我的类的代码,其对象需要在 LoadCategoryEntity 中自动装配

@Service("categoryLoadService")
@Transactional
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS,value="request")
public class CategoryEntityLoadService implements EntitiesLoadService {


    private AbstractHibernateDAO categDAO;

    @Autowired
    @Qualifier("categDAO")
    public void setCategDAO(AbstractHibernateDAO categDAO) {
        this.categDAO = categDAO;
    }

这是我的 DAO

@Repository("categDAO")
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS,value="request")
public class CategoryDAO extends AbstractHibernateDAO<category_pojo>{

}

我已经向 VM -javaagent:C:\Users\XXX\Desktop\UserLibrary\spring-agent-2.5.6.jar 提供了 JAVAAGENT 参数

我在应用程序上下文中有以下注释

<context:load-time-weaver />

我收到很长的错误列表,所以我在粘贴看起来合适的内容

堆栈跟踪

Caused by: java.lang.NoSuchMethodError: org.springframework.transaction.aspectj.AbstractTransactionAspect.invokeWithinTransaction(Ljava/lang/reflect/Method;Ljava/lang/Class;Lorg/springframework/transaction/interceptor/TransactionAspectSupport$InvocationCallback;)Ljava/lang/Object;
    at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:63)
    at com.ClickToShop.Service.UserServiceImpl.setUserDAO(UserServiceImpl.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:594)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    ... 39 more
Aug 21, 2013 10:34:57 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet MyDispatcherServlet
java.lang.NoSuchMethodError: org.springframework.transaction.aspectj.AbstractTransactionAspect.invokeWithinTransaction(Ljava/lang/reflect/Method;Ljava/lang/Class;Lorg/springframework/transaction/interceptor/TransactionAspectSupport$InvocationCallback;)Ljava/lang/Object;
    at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:63)
    at com.ClickToShop.Service.UserServiceImpl.setUserDAO(UserServiceImpl.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:594)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:314)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:558)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

也有很多这样的消息

when weaving classes 
when weaving 
 [Xlint:cantFindType]
[WebappClassLoader@1bcdbf6] error can't determine annotations of missing type org.springframework.cache.annotation.CachePut
when weaving type org.springframework.aop.framework.CglibAopProxy$HashCodeInterceptor
when weaving classes 
when weaving 
 [Xlint:cantFindType]
[WebappClassLoader@1bcdbf6] error can't determine annotations of missing type org.springframework.cache.annotation.Cacheable
when weaving type org.springframework.aop.framework.CglibAopProxy$HashCodeInterceptor
when weaving classes 
when weaving 
 [Xlint:cantFindType]
[WebappClassLoader@1bcdbf6] error can't determine annotations of missing type org.springframework.cache.annotation.CacheEvict
when weaving type org.springframework.aop.framework.CglibAopProxy$ProxyCallbackFilter
when weaving classes 
when weaving 
 [Xlint:cantFindType]
4

0 回答 0