Spring MVC - Send email, Bean creation - email

I'm trying to set up my Spring MVC app to send email, but i think i'm doing something wrong in the configuration
In My AppConfig i instantiate the Bean:
#Bean
public JavaMailSender mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setDefaultEncoding("UTF-8");
return mailSender;
}
Then in my application.properties I have:
mail.port= 465
mail.host= smtp.gmail.com
mail.username= username
mail.password= password
emailTo = info#beingsmart.it
emailSubject = ALERT - ePark Server
mail.smtp.auth = true
mail.smtp.starttls.enable = true
mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.properties.mail.smtp.socketFactory.fallback = false
When I try to send the email i'm getting
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.mail.javamail.JavaMailSender]: Factory method 'mailSender' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/mail/AuthenticationFailedException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 49 more
Caused by: java.lang.NoClassDefFoundError: javax/mail/AuthenticationFailedException
at it.besmart.config.AppConfig.mailSender(AppConfig.java:128)
at it.besmart.config.AppConfig$$EnhancerBySpringCGLIB$$b2a09c0.CGLIB$mailSender$7(<generated>)
at it.besmart.config.AppConfig$$EnhancerBySpringCGLIB$$b2a09c0$$FastClassBySpringCGLIB$$dd65f050.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)
at it.besmart.config.AppConfig$$EnhancerBySpringCGLIB$$b2a09c0.mailSender(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 50 more
Caused by: java.lang.ClassNotFoundException: javax.mail.AuthenticationFailedException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 61 more
EDIT
I added javax mail to my pom
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.6</version>
</dependency>
Now I have a different exception when trying to send the email
java.lang.NoClassDefFoundError: com/sun/mail/util/MessageRemovedIOException
It looks like an authentication error, but i'm thinking that JavaMailSender does not takes the setting in my application.properties, could it be?
Thanks

It seems to be missing dependency rather than anything else. If using spring boot have dependency like:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
If you don't I suggest you look inside that POM and figure out what are the missing pieces.
In your particular case it seems you need:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.5</version>
</dependency>
Generic advice:
ClassNotFoundException means class which you need is not on classpath. It's usually a missing dependency
Google to find which jar contains the missing class
Find the library it on maven central
Add to dependencies

Related

Quarkus Using Reactive Hibernate: Parameter 'dataSource' may not be null

I'm trying to switch from tranditional database accessing to reactive. In pom.xml i have added:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>
and in application.properties:
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=postgres
quarkus.datasource.password=pw
quarkus.datasource.reactive.url = postgresql://localhost:5432/postgres
quarkus.datasource.jdbc = false
When i start Quarkus there is the error:
ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): java.lang.IllegalArgumentException: Parameter 'dataSource' may not be null
at org.wildfly.common.Assert.checkNotNullParamChecked(Assert.java:71)
at org.wildfly.common.Assert.checkNotNullParam(Assert.java:49)
at org.wildfly.security.auth.realm.jdbc.QueryConfiguration.<init>(QueryConfiguration.java:40)
at org.wildfly.security.auth.realm.jdbc.QueryBuilder.buildQuery(QueryBuilder.java:97)
at org.wildfly.security.auth.realm.jdbc.JdbcSecurityRealmBuilder.build(JdbcSecurityRealmBuilder.java:55)
at io.quarkus.elytron.security.jdbc.JdbcRecorder.createRealm(JdbcRecorder.java:42)
at io.quarkus.deployment.steps.ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig173765586.deploy_0(Unknown Source)
at io.quarkus.deployment.steps.ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig173765586.deploy(Unknown Source)
at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
at io.quarkus.runtime.Application.start(Application.java:101)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:110)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:70)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:43)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:123)
at io.quarkus.runner.GeneratedMain.main(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:104)
at java.base/java.lang.Thread.run(Thread.java:833)
These are the reasons of the problem and the approaches to fix that:
Did you set the dataSource parameter in the ReactiveHibernate constructor? If not, you can do that using the #ConfigProperty annotation
Check if the parameter is not null or has a valid value.

failed to load org.mariabd.jdbc.Driver

I have a Spring app that runs fine from the IDE with local mariadb using the mariadb 2.7.4 in the POM as below but I get the error second below running it on Ubuntu. I have removed the mysql connector and still the problem. Any help to why the discrepancy and soution?
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.4</version>
</dependency>
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.mariadb.jdbc.Driver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
... 173 more
Caused by: java.lang.IllegalStateException: Cannot load driver class: org.mariadb.jdbc.Driver
at org.springframework.util.Assert.state(Assert.java:94)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:223)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:175)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:85)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 174 more
I needed to explicity include the driver in the war. In the IDE it was implicitlly included. Sorry for the trivial answer that should have been pre-discovered.

Unable to connect app to postgres server using yaml files

Following Error while connecting springboot app service to Postgres using yml.
NOTE: url: jdbc:postgresql://localhost/postgres
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#3f0846c6' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f0846c6': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1429)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636)
... 62 common frames omitted
Caused by: java.net.UnknownHostException: db
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at org.postgresql.core.PGStream.<init>(PGStream.java:75)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
... 138 common frames omitted
Please suggest the alternatives and ideas
Well, you did not show your yaml file, that is most important. Error says problem with connection, so make sure your postgres is up and running, you can test it in console like
psql -h localhost -p port(default 5432) -U username -d database
spring:
datasource:
url: jdbc:postgresql://localhost:5432/databaseName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false
username: yourUsername
password: yourPassword
jpa:
hibernate:
ddl-auto: update
show-sql: true
This is example of application.yaml for connecting to postgresql running on your machine, i am using docker for databases,so it works for that as well. Then make sure you have postgresql in your build file. If you use maven, it looks like this
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
And don`t forget JPA, which you probably have, as i see from error, but anyway
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Version is defined as parent. Spring boot makes configuration and connection for you, just by adding dependencies and reading your application.yml file.

Exception in thread "main" java.io.IOException: Cannot initialize Cluster

I am trying to run a simple Hadoop Map reduce program on eclipse in windows. Iam getting the following exception.
Exception in thread "main" java.io.IOException: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses.
at org.apache.hadoop.mapreduce.Cluster.initialize(Cluster.java:121)
at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:83)
at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:76)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1188)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1184)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Unknown Source)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
at org.apache.hadoop.mapreduce.Job.connect(Job.java:1183)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:1212)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1236)
at com.hadoop.mapreduce.WordCountDriverClass.main(WordCountDriverClass.java:41)
These are the jar files I have added in the project.
com.google.guava_1.6.0.jar
commons-configuration-1.7.jar
commons-lang-2.6.jar
commons-logging-1.1.3.jar
commons.collections-3.2.1.jar
guava-13.0.1.jar
hadoop-annotations-2.7.2.jar
hadoop-auth-2.6.0.jar
hadoop-common-2.3.0.jar
hadoop-common.jar
hadoop-mapreduce-client-core-2.0.2-alpha.jar
hadoop-mapreduce-client-core-2.7.2.jar
hadoop-mapreduce-client-jobclient-2.2.0.jar
hadoop-test-1.2.1.jar
log4j-1.2.17.jar
slf4j-api-1.7.7.jar
slf4j-simple-1.6.1.jar
I have added those jar files after checking the exception messages in the console. But I couldn't understand this exception.
Can anyone please help me fixing this.
This is my driver class.
Configuration conf = new Configuration();
// Creating a job
Job job = Job.getInstance(conf,"WordCountDriverClass");
job.setJarByClass(WordCountDriverClass.class);
job.setMapperClass(WordCountMapper.class);
job.setReducerClass(WordCountReducer.class);
job.setNumReduceTasks(2);
job.setInputFormatClass(KeyValueTextInputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path("inputfiles"));
FileOutputFormat.setOutputPath(job, new Path("outputfiles"));
job.waitForCompletion(true);
Looks like you are running the wordcount example, what it requires are 1.2.1 hadoop-core and 2.2.0 hadoop-common. If you use Maven instead, the config should be as simple as
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.2.0</version>
</dependency>

error in deploying a SpringBoot webapp into tomcat with MongoDB

I am new to SpringBoot . I have successfully executed a webapp using springboot with embedded tomcat.Facing issue when trying to deploy this spring boot webapp into a external Tomcat server.
I got bellow error
Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5456) [catalina.jar:7.0.54]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.54]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_60]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 26 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 28 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 40 common frames omitted
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:180) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:121) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 41 common frames omitted
2016-03-23 11:55:09.834 INFO 8268 --- [ost-startStop-1] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/classes/, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/aopalliance-1.0.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/classmate-1.1.0.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/hibernate-validator-5.2.4.Final.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jackson-annotations-2.6.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jackson-core-2.6.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jackson-databind-2.6.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jboss-logging-3.3.0.Final.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jcl-over-slf4j-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jul-to-slf4j-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/log4j-over-slf4j-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/logback-classic-1.1.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/logback-core-1.1.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/mongo-java-driver-2.13.3.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/mysql-connector-java-5.1.38.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/slf4j-api-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/snakeyaml-1.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-aop-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-beans-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-autoconfigure-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-data-mongodb-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-logging-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-security-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-validation-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-web-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-context-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-core-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-data-commons-1.11.4.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-data-mongodb-1.8.4.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-expression-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-jdbc-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-orm-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-security-config-4.0.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-security-core-4.0.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-security-web-4.0.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-tx-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-web-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-webmvc-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/validation-api-1.1.0.Final.jar]
2016-03-23 11:55:09.839 ERROR 8268 --- [ina-startStop-1] org.apache.catalina.core.ContainerBase : A child container failed during start
I am using spring boot 1.3.3 with jdk7.
any help would be good - as anyone had similar problems when deploying spring boot apps as a WAR into a external server?
Here are my files
pom.xml
<project.......>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<groupId>SpringBootDemo</groupId>
<artifactId>SpringBootDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootDemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>
<finalName>SpringBootDemo</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
ApplicatationStart.java
package com.springDemo;
#Configuration
#ComponentScan(basePackages="com.springDemo")
#EnableAutoConfiguration
#SpringBootApplication
public class ApplicatationStart extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ApplicatationStart.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(ApplicatationStart.class, args);
}
}
application.properties
server.contextPath =/springDemo
#for mongo db
spring.data.mongodb.uri=mongodb://localhost/admin
#spring.data.mongodb.host=localhost
#spring.data.mongodb.port=27017
# security properties
security.basic.enabled=false
management.security.enabled=false
The point is that the spring-boot-starter-security is pulling the spring-jdbc dependency. This dependency triggers the DataSourceAutoConfiguration to create a DataSource as you haven't defined one explicitly it assumes an in memory on like H2, HSQLDB or Derby. However those aren't on your classpath so startup fails.
Now you have 2 options to fix this. The first is the explicitly disable the DataSourceAutoConfiguration by adding it as an exclude to the #SpringBootApplication annotation.
#SpringBootApplication(exclude= DataSourceAutoConfiguration.class)
public class ApplicatationStart extends SpringBootServletInitializer { ... }
Pro Tip: You should also remove the #Configuration, #ComponentScan and #EnableAutoConfiguration as those are implied by #SpringBootApplication.
The other option is to exclude the spring-jdbc dependency from the spring-boot-starter-security dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<excludes>
<exclude>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</exclude>
</excludes>
</dependency>