java依赖异常,java – 注入自动连线依赖关系失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:...

我正在使用

Spring,Hibernate,Struts和Maven创建Web应用程序.

当我运行mvn clean install命令时,我得到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.project.action.PasswordHintActionTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.project.action.PasswordHintAction com.project.action.PasswordHintActionTest.action; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.project.action.PasswordHintAction] 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)}

以下是具有自动连线依赖关系的类:

import com.opensymphony.xwork2.Action;

import org.project.model.User;

import org.proejct.service.UserManager;

import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;

import org.subethamail.wiser.Wiser;

import static org.junit.Assert.*;

public class PasswordHintActionTest extends BaseActionTestCase {

@Autowired

private PasswordHintAction action;

@Autowired

private UserManager userManager;

@Test

public void testExecute() throws Exception {

// start SMTP Server

Wiser wiser = new Wiser();

wiser.setPort(getSmtpPort());

wiser.start();

action.setUsername("user");

assertEquals("success", action.execute());

assertFalse(action.hasActionErrors());

// verify an account information e-mail was sent

wiser.stop();

assertTrue(wiser.getMessages().size() == 1);

// verify that success messages are in the request

assertNotNull(action.getSession().getAttribute("messages"));

}

}

我的applicationcontext.xml

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"

default-lazy-init="true">

我已经添加到我的上下文配置来扫描AutoWired依赖项.但我不知道为什么它仍然给这个例外.

我尝试以下列方式添加它,但我仍然得到相同的异常

更新:

以下是密码提示操作

import org.project.model.User;

import com.project.webapp.util.RequestUtil;

import org.springframework.mail.MailException;

import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.ArrayList;

import java.util.List;

public class PasswordHintAction extends BaseAction {

private static final long serialVersionUID = -4037514607101222025L;

private String username;

/**

* @param username The username to set.

*/

public void setUsername(String username) {

this.username = username;

}

/**

* Execute sending the password hint via e-mail.

*

* @return success if username works, input if not

*/

public String execute() {

List args = new ArrayList();

// ensure that the username has been sent

if (username == null) {

log.warn("Username not specified, notifying user that it's a required field.");

args.add(getText("user.username"));

addActionError(getText("errors.requiredField", args));

return INPUT;

}

if (log.isDebugEnabled()) {

log.debug("Processing Password Hint...");

}

// look up the user's information

try {

User user = userManager.getUserByUsername(username);

String hint = user.getPasswordHint();

if (hint == null || hint.trim().equals("")) {

log.warn("User '" + username + "' found, but no password hint exists.");

addActionError(getText("login.passwordHint.missing"));

return INPUT;

}

StringBuffer msg = new StringBuffer();

msg.append("Your password hint is: ").append(hint);

msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(getRequest()));

mailMessage.setTo(user.getEmail());

String subject = '[' + getText("webapp.name") + "] " + getText("user.passwordHint");

mailMessage.setSubject(subject);

mailMessage.setText(msg.toString());

mailEngine.send(mailMessage);

args.add(username);

args.add(user.getEmail());

saveMessage(getText("login.passwordHint.sent", args));

} catch (UsernameNotFoundException e) {

log.warn(e.getMessage());

args.add(username);

addActionError(getText("login.passwordHint.error", args));

getSession().setAttribute("errors", getActionErrors());

return INPUT;

} catch (MailException me) {

addActionError(me.getCause().getLocalizedMessage());

getSession().setAttribute("errors", getActionErrors());

return INPUT;

}

return SUCCESS;

}

}

更新2:

的applicationContext-struts.xml中:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值