在Spring中混合使用Scoped代理和@configurable Annotation

时间:2013-08-21 05:08:12

标签: spring hibernate aspectj

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

我了解到可以使用ASPECT J对使用new keyword创建的对象进行自动装配。所以我尝试配置它。 我正在使用我的eclipse和内置的tomcat 6和NO构建工具。

1.scoped代理bean使用cglib配置并完美运行。 然后,我创建工厂来创建具体对象。 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;
}

}

这是我的类别,由混凝土工厂创建,并且需要自动生产其他一些受限制的代理豆(在我的情况下是服务)

@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参数 -javaagent:C:\用户\ XXX \桌面\ UserLibrary \弹簧剂2.5.6.jar

我在应用程序上下文注释

<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]

0 个答案:

没有答案