当前位置: 首页 > 知识库问答 >
问题:

从3升级到spring之后。x到4.3.2,JavaMailSender和VelocityEngine的自动连接失败

卓嘉良
2023-03-14

原因:org。springframework。豆。工厂BeanCreationException:无法自动关联字段:私有组织。springframework。邮政javamail。JavaMailSender.com。xxx。服务impl。NotificationServiceImpl。邮件发送者;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:找不到[org.springframework.mail.javamail.JavaMailSender]类型的符合依赖项条件的bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

应用程序上下文。xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"
   default-lazy-init="true">
<!-- Enable @Transactional support -->
<tx:annotation-driven/>

<!-- Enable @AspectJ support -->
<aop:aspectj-autoproxy/>

<!-- Activates scanning of @Autowired -->
<context:annotation-config/>

<!-- Activates scanning of @Service -->
<context:component-scan base-package="com.xxx.service"/>

<bean id="userSecurityAdvice" class="com.xxx.service.UserSecurityAdvice"/>

<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" autowire="byName">
    <property name="host" value="${mail.host}" />
    <property name="port" value="${mail.port}" />
    <property name="username" value="${mail.username}" />
    <property name="password" value="${mail.password}" />
    <property name="javaMailProperties">
       <props>
              <prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
              <prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
              <prop key="mail.from">${mail.from}</prop>
           </props>
    </property>
</bean>

<!-- Configure Velocity for sending e-mail -->
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    <property name="velocityProperties">
        <props>
            <prop key="resource.loader">class</prop>
            <prop key="class.resource.loader.class">
                org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
            </prop>
            <prop key="velocimacro.library"></prop>
        </props>
    </property>
</bean>

其他依赖项:

  • javax。邮件-1.4.7
package com.xxx.service.impl;

@Service("notificationService")
public class NotificationServiceImpl implements NotificationService {
    @Autowired
    private JavaMailSender mailSender;
}

所有依赖项都已正确添加,JavaMailSender类也存在于spring-context-support-xxx.jar中,但找不到它没有自动运行的原因。有人能帮忙吗?

共有1个答案

黎曾笑
2023-03-14

尝试从. m2目录中删除Spring文件夹。然后更新您的maven依赖项并重建项目。

 类似资料:
  • 在部署应用程序时,我会遇到以下异常。 该组件为: 而该组件的自动连接是: FunnelStateHolderMapper接口 在包含此代码所在包的配置中有一个组件扫描。 这在Spring3中工作得很好,但是自从切换到Spring5之后,这个问题就出现了。我想可能是我为了编译它而进行的一些重构导致了这个问题,但我不这么认为。以上代码所在的文件均未更新。 到目前为止,我还没有更新任何spring配置。

  • 我正在将grails应用程序从grails 2.5.4升级到3.1.9,我在ajax调用方面遇到了问题。 我有gsp模板在我的应用程序中使用ajax请求从服务器异步加载数据。这里是其中一个。 下面的javascript调用激活ajax请求。 这将成功调用以下控制器操作。 直到这一刻,一切都按预期进行。比它应该呈现以下gsp模板,但它没有。该属于它的地方空着,控制台没有错误 我不得不重新将资源插件中

  • 应用程序抛出以下错误: org.springframework.beans.factory.NoUniqueBean定义异常:没有定义[org.springframework.transaction.PlatformTransactionManager]类型的合格bean:预期的单个匹配bean,但找到3 大家好,我们有一个webapp,我们升级到了上面的配置,它在java 8、tomcat 8上

  • 我将应用程序迁移到了laravel 5.7。在composer.json中安装软件包时,我将“maatwebsite/excel:~2.1.0”升级到“maatwebsite/excel”:“^3.1”。因此,现在我的导出功能不再工作。我尝试在中跟踪升级https://docs.laravel-excel.com/3.1 但不适用于我。这是旧版本中使用的旧代码:

  • 如果您打算升级一个早先版本的 Jekyll,那么一些发生在 1.0 及 2.0 版本中的相关变化,您需要首先了解下。 在我们开始动手之前,请先获取最新版本的 Jekyll: $ gem update jekyll 立即开始 想快速构建并运行一个全新的 Jekyll 站点吗?那么只要执行 jekyll new SITENAME 即可!该命令会创建一个包含了 Jekyll 最基础框架的文件夹。 Jek