I have an EmailService EJB that has a very simple \'send_email\' method. I\'m receving the error in the title despite clearly having a public constructor that does not take para
I would prefer to annotate your constructor with @Inject
instead:
@Stateless
@LocalBean
public class EmailService {
....
@Deprecated
public EmailService(){}
@Inject
public EmailService(ContextFinder ctf) {
username = (String) ctf.lookup(EMAIL_USERNAME_JNDI_NAME);
password = (String) ctf.lookup(EMAIL_PASSWORD_JNDI_NAME);
server = (String) ctf.lookup(SMTP_SERVER_JNDI_NAME);
port = (Integer) ctf.lookup(SMTP_PORT_JNDI_NAME);
}
...
}
>> Using @PostConstruct
is not exactly the same as you had. init()
method will not work outside the container like in JUnit test.
You still need to provide the default not parametrized constructor (part of the The EJB 3.1 spec, section 4.9.2 Bean Classes).