gpt4 book ai didi

java - spring从3.x升级到4.3.2后,JavaMailSender和VelocityEngine的 Autowiring 失败

转载 作者:太空宇宙 更新时间:2023-11-04 12:03:51 25 4
gpt4 key购买 nike

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.mail.javamail.JavaMailSender com.xxx.service.impl.NotificationServiceImpl.mailSender; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

applicationContext.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.mail - 1.4.7
  • org.apache.velocity - 1.7
<小时/>
package com.xxx.service.impl;

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

所有依赖项均已正确添加,JavaMailSender 类也存在于 spring-context-support-xxx.jar 中,但找不到它未 Autowiring 的原因。有人可以帮忙吗?

最佳答案

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

关于java - spring从3.x升级到4.3.2后,JavaMailSender和VelocityEngine的 Autowiring 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40625763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com