1

在我的应用程序中,我尝试连接到不同的应用程序并保存数据。在那部分中,我成功地保存了该数据。但问题是当我保存电子邮件时,它必须触发预定义的电子邮件建议。但它没有发生。这是我在这个问题中解释的连接代码,而我在其他应用程序的 servlet 中的代码是。

ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

String uname = request.getParameter("userName");
String pwd = request.getParameter("pwd");
String email = request.getParameter("email");

userDao.insertUser(user);
passDao.insertPassword(password);

User u1 =userDao.getUser(domain, uname);

Email command = new Email();

command.setCreationDate(new Date());
command.setAddress(email);
command.setUser(u1);
command.setLocale(new Locale("en","US"));

log.debug("Upto user adding data");

JosService josService = (JosService)context.getBean("josService");

try {
    log.debug("before adding email data");
    josService.insertEmail(u1,command);
    log.debug("After adding email data");
} catch (Exception e) {
    log.error("Setting and sending email address is failed");
    e.printStackTrace();
}

log.debug("Data saved succesfully");
response.setStatus(200);

在我的 applicationcontext.xml 中有这样定义的建议

<!-- ================ ADVISOR DEFINITIONS ================ -->
<bean id="emailAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    <property name="advice">
        <ref local="insertEmailAfterReturningAdvice" />
    </property>
    <property name="pattern">
        <value>.*insertEmail</value>
    </property>
</bean>

<!-- ================ ADVICE DEFINITIONS ================ -->
<bean id="insertEmailAfterReturningAdvice" class="cn.net.openid.jos.service.InsertEmailAfterReturningAdvice">
    <constructor-arg>
        <ref local="emailConfirmationInfoSendTaskExecutor" />
    </constructor-arg>
</bean>

<bean id="emailConfirmationInfoSendTaskExecutor" class="cn.net.openid.jos.service.EmailConfirmationInfoSendTaskExecutor">
    <constructor-arg ref="taskExecutor" />
    <property name="mailSender" ref="mailSender" />
    <property name="passwordDao" ref="passwordDao" />
</bean>
4

0 回答 0