gulixiang520
2011-08-23 10:06
浏览 255
已采纳

spring和freemarker 总是提示freemarkerResult这个类没有找到,不能注入,但是程序也能运行

 

我用的框架是struts2+spring+mybatis 

 

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - No bean named 'org.apache.struts2.dispatcher.ServletActionRedirectResult' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@11fb2e0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,textBookInfoService,tidingsService,treeService,universityService,userService,veneratorService,dataSource,transactionManager,sqlSessionFactory,sqlSessionTemplate,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,transactionPointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0]; root of factory hierarchy

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - Ignoring constructor [public org.apache.struts2.dispatcher.ServletActionRedirectResult(java.lang.String,java.lang.String,java.lang.String,java.lang.String)] of bean 'org.apache.struts2.dispatcher.ServletActionRedirectResult': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.dispatcher.ServletActionRedirectResult': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

TRACE o.s.b.factory.support.DefaultListableBeanFactory - Ignoring constructor [public org.apache.struts2.dispatcher.ServletActionRedirectResult(java.lang.String,java.lang.String,java.lang.String)] of bean 'org.apache.struts2.dispatcher.ServletActionRedirectResult': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.dispatcher.ServletActionRedirectResult': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

TRACE o.s.b.factory.support.DefaultListableBeanFactory - Ignoring constructor [public org.apache.struts2.dispatcher.ServletActionRedirectResult(java.lang.String,java.lang.String)] of bean 'org.apache.struts2.dispatcher.ServletActionRedirectResult': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.dispatcher.ServletActionRedirectResult': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - Ignoring constructor [public org.apache.struts2.dispatcher.ServletActionRedirectResult(java.lang.String)] of bean 'org.apache.struts2.dispatcher.ServletActionRedirectResult': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.dispatcher.ServletActionRedirectResult': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - Not autowiring property 'actionMapper' of bean 'org.apache.struts2.dispatcher.ServletActionRedirectResult' by name: no matching bean found

 

 

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - No bean named 'org.apache.struts2.views.freemarker.FreemarkerResult' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@11fb2e0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,adminAction,analysisAction,imitationTestAction,informationManageAction,leaderManageAction,scoreAction,statisticAction,toamendActionorg.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0]; root of factory hierarchy

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - Ignoring constructor [public org.apache.struts2.views.freemarker.FreemarkerResult(java.lang.String)] of bean 'org.apache.struts2.views.freemarker.FreemarkerResult': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.views.freemarker.FreemarkerResult': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

TRACE o.s.b.factory.support.DefaultListableBeanFactory - Not autowiring property 'freemarkerManager' of bean 'org.apache.struts2.views.freemarker.FreemarkerResult' by name: no matching bean found

 TRACE o.s.b.factory.support.DefaultListableBeanFactory - Not autowiring property 'writer' of bean 'org.apache.struts2.views.freemarker.FreemarkerResult' by name: no matching bean found

 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • myali88 2011-08-23 13:25
    已采纳

    [quote]
    一句话惊醒梦中人啊,我spring用的是是注解,如何把这个检查去除能,如何去除了会不会有别的影响
    [/quote]
    这个错误你可以不用理会的,把你的日志级别调高应该就看不到这个问题了。
    至于取消依赖检查,在spring 2里面是在bean上面设置“dependency-check”来控制的,spring 3里面不再赞成使用这个了。
    你可以参考一下:
    [url]http://www.intertech.com/Blog/post/Spring-Dependency-Check-Deprecated.aspx[/url]
    [url]http://www.mkyong.com/spring/spring-properties-dependency-checking/[/url]

    点赞 打赏 评论
  • myali88 2011-08-23 11:17

    [code="java"]
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.dispatcher.ServletActionRedirectResult'
    [/code]
    这个产生的原因是struts把创建对象委托给了spring,而ServletActionRedirectResult在创建时一些依赖属性没有设置,所以报错。不过这个不能算错误,你把日志级别提高应该就看不到(你现在用了TRACE),或者把spring配置的依赖检查设置为false。从SpringObjectFactory的实现里,你也能看到:
    [code="java"]
    public Object buildBean(Class clazz, Map extraContext) throws Exception {
    Object bean;

        try {
            // Decide to follow autowire strategy or use the legacy approach which mixes injection strategies
            if (alwaysRespectAutowireStrategy) {
                // Leave the creation up to Spring
                bean = autoWiringFactory.createBean(clazz, autowireStrategy, false);
                injectApplicationContext(bean);
                return injectInternalBeans(bean);
            } else {
                bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
                bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean, bean.getClass().getName());
                // We don't need to call the init-method since one won't be registered.
                bean = autoWiringFactory.applyBeanPostProcessorsAfterInitialization(bean, bean.getClass().getName());
                return autoWireBean(bean, autoWiringFactory);
            }
        } catch (UnsatisfiedDependencyException e) {
            //错误是从这里出来的,不过后面的方法又重新创建了对象,所以这个异常可以不管
            if (LOG.isErrorEnabled())
                LOG.error("Error building bean", e);
            // Fall back
            return autoWireBean(super.buildBean(clazz, extraContext), autoWiringFactory);
        }
    }
    

    [/code]

    点赞 打赏 评论

相关推荐 更多相似问题