spring 的aop,急

08-05-27 xingyuanjian

最近参照spring自带的jpetstore列子,试试那关于面向切面编程,而我想做的就是,在没个用户注册成功之后,系统根据applicationContext.xml里的配置自动发邮件给用户注册的邮箱中。
在applicationContext.xml中的配置如下:

<aop:config>
<aop:advisor pointcut="execution(* *..longHuaFacade.*(..))" advice-ref="txAdvice"/>
<aop:advisor pointcut="execution(* *..longHuaFacade.saveUser(*..user))" advice-ref="emailAdvice"/>
</aop:config>

<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="save*"/>
<tx:method name="update*"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<bean id="emailAdvice" class="com.longHua.domain.logic.SendRegConfirmationEmailAdvice">
<property name="mailSender" ref="mailSender"/>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.host}"/>
</bean>
那个门面接口代码如下:
public interface longHuaFacade {
void saveUser(UserReg user);
void delete(int id);
UserReg getUser(int id);
List<UserReg> getUsers();
List<UserReg> checkRegName(String regName);
List<UserReg> checkRegEmail(String regEmail);
}



当注册成功之后,我发现我设置的根本就没点反应,,不知道是不是我配错了,
SendRegConfirmationEmailAdvice里的代码如下:

package com.longHua.domain.logic;

import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import com.longHua.domain.UserReg;


public class SendRegConfirmationEmailAdvice implements AfterReturningAdvice, InitializingBean {

private static final String DEFAULT_MAIL_FROM = "xingyuanjian@sina.com";

private static final String DEFAULT_SUBJECT = "欢迎你注册——龙华电子商务!";

private final Log logger = LogFactory.getLog(getClass());

private MailSender mailSender;

private String mailFrom = DEFAULT_MAIL_FROM;

private String subject = DEFAULT_SUBJECT;

public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}

public void setMailFrom(String mailFrom) {
this.mailFrom = mailFrom;
}

public void setSubject(String subject) {
this.subject = subject;
}

public void afterPropertiesSet() throws Exception {
if (this.mailSender == null) {
throw new IllegalStateException("mailSender is required");
}
}

public void afterReturning(Object returnValue, Method m, Object[] args, Object target) throws Throwable {
UserReg userReg = (UserReg) args[0];
if (userReg.getUserMail() == null || userReg.getUserMail().length() == 0) {
return;
}

StringBuffer text = new StringBuffer();
text.append(userReg.getUserName()).append("你好");
text.append(",欢迎你在我们龙华电子商务注册,请确认你注册的信息,你的用户名是: ").append(userReg.getUserName()).append("<br>");
text.append("你的登陆密码是:").append(userReg.getUserPwd());

SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(userReg.getUserMail());
mailMessage.setFrom(this.mailFrom);
mailMessage.setSubject(this.subject);
mailMessage.setText(text.toString());
try {
this.mailSender.send(mailMessage);
}
catch (MailException ex) {
logger.warn("An exception occured when trying to send email", ex);
}
}

}


其实所有的代码和jpetstore里的类似,

真的希望你们能帮我解决....

xingyuanjian
2008-05-27 15:15

就算简单也帮我看看好吗????
在线等....

xingyuanjian
2008-05-27 22:09

我晕!!!!!!!!!!!!!

bicity
2008-05-28 10:49

不用这么急的吧,才一天不到,你就等不下去啦!
顺便说一下,我没怎么研究过这个!

banq
2008-05-28 11:40

这属于正常调试问题,自己使用Eclipse断点调试跟踪每一步。
Java是组件技术,涉及方方面面碎块很多,别人帮你找错会花费很长时间。这是很浪费别人的时间,也是浪费自己的时间。

2Go 1 2 下一页