I have a project using spring-boot and added
the following dependency in my build.gradle:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.5.7.RELEASE'
My application.properties contains
SMTP Configuration
spring.mail.host=mail.xxx
spring.mail.port=587
spring.mail.username=donotreply#xxx
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.from=donotreply#xxx
According to multiple answers here and documentations i found,that should be enought to create the bean with this settings.
I now want to use a mailer in a Service class
#Autowired
private JavaMailSender emailSender;
[...]
#Value("${spring.mail.host}")
private String mailHost;
When i try to send a message using emailSender i get the following error:
Mail server connection failed; nested exception is
com.sun.mail.util.MailConnectException: Couldn't connect to host,
port: localhost, 25; timeout -1; nested exception is:
java.net.ConnectException: Connection refused: connect. Failed
messages: com.sun.mail.util.MailConnectException: Couldn't connect to
host, port: localhost, 25; timeout -1; nested exception is:
java.net.ConnectException: Connection refused: connect
Obviously it is trying to connect to localhost instead of the configured host.
The variable mailHost does contain the correct value, so the properties are read correct.
EDIT:
The autowired class for emailSender is org.springframework.mail.javamail.JavaMailSenderImpl, which seems to be correct to me.
In my case, the reason was that I instantiated the bean myself like this:
#Bean
public JavaMailSender mailSender() throws IOException {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setDefaultEncoding("UTF-8");
return mailSender;
}
Not sure why, but that way, it ignores the application.properties. Maybe the reason was, that I explicitly instantiated JavaMailSenderImpl to set a default encoding and possibly that implementation isn't application.properties aware?
However, removing that bean solved the problem.
[FOUND]
A co-worker was working on the same and had commited an incomplete bean definition. That bean was autowired.
Related
I am using Weblogic 12c and I have configured my datasources like this:
Notice that they are all deployed on target "AdminServer". Also, the "Name" field and "JNDI Name" field are identical. For example, suppose one datasource's name is "MYDS".
Now, when I try to acquire that datasource through Spring Data JPA like this:
#Bean
#Primary
public DataSource businessDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
dataSource.setResourceRef(true);
dataSource.setJndiName("MYDS");
dataSource.afterPropertiesSet();
return (DataSource) dataSource.getObject();
}
I get the following error when trying to deploy the war file to weblogic:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [javax.sql.DataSource]: Factory method
'businessDataSource' threw exception; nested exception is
javax.naming.NameNotFoundException: Unable to resolve 'MYDS'. Resolved
''; remaining name 'MYDS'
Also I see this error:
DEBUG o.s.jndi.JndiObjectFactoryBean - Converted JNDI name
[java:comp/env/MYDS] not found - trying original name [MYDS].
javax.naming.NameNotFoundException: While trying to look up
comp/env/MYDS in /app/myapp/webclient/404708050.; remaining name
'comp/env/MYDS'
Just looking at the source for setResourceRef and it states :
public void setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a Java EE container,
i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it.
Default is "false".
Note: Will only get applied if no other scheme (e.g. "java:") is given.
If you are setting it to true have you tried adding java:comp/env/ to the JNDI name ?
I'm trying to do Remote EJB calls to my Wildfly 10/JBoss 7 EAP server, but keep getting Invalid User error messages on my Wildfly server (my EJB is called LoginManager):
23:04:02,872 ERROR [org.jboss.as.ejb3.invocation] (default task-6) WFLYEJB0034: EJB Invocation failed on component LoginManager for method public abstract java.lang.String ejbs.LoginManagerRemote.echo(java.lang.String): javax.ejb.EJBAccessException: WFLYSEC0027: Invalid User
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:69)
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:49)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:97)
I've added my user to the application-users.properties file using the add-user.sh/bat scripts.
I've tried putting in breakpoints in the Wildfly server itself in the SecurityContextInterceptor class on line 54 and see that the principal is null:
if (holder.skipAuthentication == false) {
holder.securityManager.authenticate(holder.runAs, holder.runAsPrincipal, holder.extraRoles);
I'm not entirely sure if this runAs or runAsPrincipal is the principal/credentials passed by the remote EJB invocation, but I suspect it might be responsible for my problem.
I'm calling the remote ejb as:
Properties p = new Properties();
p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(p);
LoginManagerRemote ejb = (LoginManagerRemote) context.lookup("ejb:ear-1.0/ejbs-1.0//LoginManager!ejbs.LoginManagerRemote");
return ejb.echo("test");
with my jboss-ejb-client.properties as:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.conncetion.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
remote.connection.default.username=test
remote.connection.default.password=test
Am I doing something wrong? Am I missing something obvious somewhere? What do I need to do to successfully call a remote EJB?
There's a typo in your jboss-ejb-client.properties
remote.conncetion.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
Should be remote.connection.default.connect.options etc etc
I am trying to execute a method from client to server using RMI.
As long as the parameters are String, it is getting executed correctly. If I am using object as method parameter.
I am getting following exception :
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.lang.ClassNotFoundException: org.eclipse.persistence.exceptions.DatabaseException (no security manager: RMI class loader disabled)
Server configuration:
#Bean
public RmiServiceExporter getUserService() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setService(userService);
exporter.setServiceName("UserService");
exporter.setServiceInterface(UserService.class);
exporter.setRegistryPort(1192);
exporter.setReplaceExistingBinding(true);
return exporter;
}
Client configuration:
public #Bean RmiProxyFactoryBean getUserService() {
RmiProxyFactoryBean rmi = new RmiProxyFactoryBean();
rmi.setServiceInterface(UserService.class);
rmi.setServiceUrl("rmi://localhost:1192/UserService");
return rmi;
}
Test code :
User user = userService.getUser(String userName);
Works perfectly fine.
userService.save(user);
Save user throws RMI exception.
I made sure that the package name for User object in server and client is same. Still I am getting the exception.
Am I missing any configuration? How can I make RMI server to load the other classes?
I have a simple application that uses hibernate to work with db. When i check connection and some methods in main method, everything is fine. But when i deploy it on server, it throws
javax.servlet.ServletException: Cant instantiate class: managed.ClientsBean.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
root cause:
com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: managed.ClientsBean.
...
root cause:
javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
...
root cause:
org.hibernate.exception.JDBCConnectionException: Could not open connection
root cause
java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/project
But I have that driver, in jboss\standalone\deployments too. How can I make jboss see it?
See here:
https://community.jboss.org/wiki/DataSourceConfigurationInAS7
And here
JDBC Postgresql driver on JBoss 7
I have a Grails app that I am hooking up to a MongoDB instance. In my Datasource.groovy, I have the following declared:
grails {
mongo {
host = "localhost"
port = 27017
databaseName = "mmib-mongo"
}
}
Mongo is installed and starts just fine.
The problem is that when I am connected to a network, using grails run-app logs the following exception:
Packaging Grails application.....
| Running Grails application
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security LDAP ...
... finished configuring Spring Security LDAP
| Error 2012-11-19 15:42:16,428 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.dao.DataAccessResourceFailureException: can't call something : MBP-C02J91TWDKQ5.local/192.168.0.131:27017/mmib-mongo; nested exception is com.mongodb.MongoException$Network: can't call something : MBP-C02J91TWDKQ5.local/192.168.0.131:27017/mmib-mongo
Message: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.dao.DataAccessResourceFailureException: can't call something : MBP-C02J91TWDKQ5.local*/192.168.0.131:27017/mmib-mongo*; nested exception is com.mongodb.MongoException$Network: can't call something : MBP-C02J91TWDKQ5.local/192.168.0.131:27017/mmib-mongo
Any clue why when I'm connected to a network, Grails/Mongo wants to use that IP Address instead of localhost, which I verified is 127.0.0.1 in /etc/hosts
Homebrew tells MongoDB to listen on only on 127.0.0.1, not your public interface or a ".local" hostname:
https://github.com/mxcl/homebrew/blob/master/Library/Formula/mongodb.rb#L95
Try deleting the bind_ip line from your local copy of mongod.conf and simply protecting port 27017 with a firewall, or else change the "bind_ip" entry in mongod.conf.