UnsatisfiedResolutionException on create instance of CDIVelocityContext
pepelara Feb 7, 2012 9:04 AMHi,
Here is my code,
@Stateful @ConversationScoped @Named public class SendMail { @Inject private Instance<MailMessage> mailMessage; @Inject private Instance<Session> session; @Inject private Instance<CDIVelocityContext> cDIVelocityContext; @Inject private ResourceProvider resourceProvider; @Inject private Messages messages; @Inject @Confirmed private Event<Person> sendMailConfirmedEventSrc; @Inject @Confirmed private Event<Exception> sendFailedExceptionEventSrc; private Person person; private String name; private String email; private boolean personValid; @Begin public void setPerson() { person = new Person(name, email); personValid = true; } @End public void cancel() { person = null; } @End public void sendHTMLVelocity() { try { mailMessage.get() .from("seam@test.test", "Seam Framework") .to(person) .subject("HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString()) .bodyHtml(new VelocityTemplate(resourceProvider.loadResourceStream("/META-INF/template.html.velocity"), cDIVelocityContext.get())) .put("version", "Seam 3") .importance(MessagePriority.HIGH) .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); sendMailConfirmedEventSrc.fire(person); } catch(SendFailedException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } catch(WeldException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } catch(UnsatisfiedResolutionException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } catch(RuntimeException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } } @End public void sendHTMLwithAlternativeVelocity() { try { mailMessage.get() .from("seam@test.test", "Seam Framework") .to(person.getEmail(), person.getName()) .subject("HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString()) .put("version", "Seam 3") .bodyHtmlTextAlt( new VelocityTemplate(resourceProvider.loadResourceStream("/META-INF/template.html.velocity"), cDIVelocityContext.get()), new VelocityTemplate(resourceProvider.loadResourceStream("/META-INF/template.text.velocity"), cDIVelocityContext.get())) .importance(MessagePriority.LOW) .deliveryReceipt("seam@jboss.org") .readReceipt("seam@jboss.org") .addAttachment("template.html.velocity", "text/html", ContentDisposition.ATTACHMENT, resourceProvider.loadResourceStream("/META-INF/template.html.velocity")) .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); sendMailConfirmedEventSrc.fire(person); } catch(SendFailedException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } catch(WeldException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } catch(UnsatisfiedResolutionException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } catch(RuntimeException e){ //sendFailedExceptionEventSrc.fire(e); e.printStackTrace(); } } public void onMailMessageComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Confirmed final Person person) { messages.info(new DefaultBundleKey("send_email_confirmed")).defaults("You have sent an email to {0}") .params(person.getName()); } public void onSendFailedException(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Confirmed final Exception e) { messages.info(new DefaultBundleKey("send_email_exception")).defaults("Thrown exception {0}") .params(e); } @Produces @Dependent public Person getPerson() { return person; } public boolean isPersonValid() { return personValid; } public void setPersonValid(boolean personValid) { this.personValid = personValid; } public String getName() { return name; } public void setName(final String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(final String email) { this.email = email; } }
When I run the webapp on JBoss AS 7.0.2.Final I get the following exception,
ERROR [stderr] (http--127.0.0.1-8180-2) org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [class org.jboss.seam.mail.templating.velocity.CDIVelocityContext]; Bindings: [@javax.enterprise.inject.Default()]
I am not sure if it is a bug, but I have been googling and tried many things and I can't get it work.
Regards,
Jose