Spring can't locate a driver class that *is* in the classpath - java

I'm trying to run a springboot app on a tomcat server that includes a datasource that's able to communicate with a vault and change db credentials during runtime. The only change I've made in this code is adding some properties that are necessary to communicate with the vault, and changing the datasource configuration to include these vault changes.
I get the following error during startup:
Description:
Cannot determine embedded database driver class for database type NONE
However, in my application.properties file I DO have the driver class specified...
spring.datasource.hikari.driverClassName=com.ibm.db2.jcc.DB2Driver
and in the pom file, I have the correct dependency so the driver is infact included in the classpath... I even see the jar in Intellij's 'External Libraries' drop down.
Again, I've not made many changes besides adding in addtional properties for our vault... and changing the code inside our datasource config to use the vault.
I've compared my changes against another module in which I did the exact same thing, and didn't have this issue at all there.
Does anyone have any ideas as to why this is happening, or suggestions on what I can try?
I've tried including a #Import annotation on my #Configuration class, which points to the vault configuration. I've tried adding a #ComponentScan on my application class to try and really get it to look at the config and properties properly.
If any further detail is required please just let me know. Thanks in advance for any and all help that can be offered.

I have faced same problem and got resolved by below annotation
#SpringDataApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
please provide code snippet.So, i can debug it.

Related

Spring-boot > implicitly auto register a 3rd party bean

This may be an impossible task, but here goes...
Is it possible to register a spring bean, by (ONLY) adding a jar to the classpath of a spring-boot application?
Scenario: I would like to create a non-intrusive plugin jar, which when imported into a spring-boot project's classpath, will automatically be picked up and provide a service (e.g. via a RestController).
Constraints
I don't want to change or reconfigure the existing spring-boot application (i.e. no additional scan paths or bean config).
I don't have any knowledge of the target spring-boot application's package structure/scan paths.
I guess I was hoping that by default Spring scan's its own package structure (i.e. org.springframework.** looking for the presence of database libs, etc) and I could piggy-back off that - I haven't had any luck (so far).
I've setup an example project in github, to further clarify/illustrate my example and attempts.
** Solution Addendum **
This bit that got it working, was to add the following file, which points to an #Configuration config file...
plugin-poc\src\main\resources\META-INF\spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.thirdpartyplugin.PluginConfiguration
I think in such cases you would try to add a spring auto configuration that is annotated with #ConditionalOnClass to be only evaluated if the given class is on the classpath. This class can register the bean and would just be evaluated if the conditional evaluates to true
Here is the relevant part of the spring boot documentation : Creating your own auto-configuration

Spring boot dependencies error gradle

I have a new spring boot project and I have included some dependencies. The thing is that on the first run the 'rest' and 'jpa' dependencies are working just fine, but on the second run I'm getting a huge error.
dependencies {
compile('org.springframework.boot:spring-boot-starter-cache')
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.boot:spring-boot-starter-social-facebook')
compile('org.springframework.boot:spring-boot-starter-social-twitter')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
The error message it the following(it was too big to paste it here):
error msg
I'm using Intelij IDEA 2016.1.1
The important error message from this stack trace seems to be:
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)
It says that you didn't define what database to use (what kind of an where it is located).
I guess you need to add some properties to your application.properties file, like:
spring.datasource.url = (URL to your data source)
spring.datasource.driverClassName = (fully qualified class name of your datasource driver)
You could use an H2 in memory database using this:
spring.datasource.url=jdbc:h2:mem:databaseName;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
Note that you also need to include the dependencies for the database into your Gradle dependencies (compile('com.h2database:h2') for an H2).
With java-errors like this you see that there are a lot of lines starting with Caused by:, this is because in the code there are many places where the code catched an exception and then threw it again.
To find the real issue you need to take a look at the last Caused by-entry:
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).
I cannot say what the issue itself is with the information you gave. But there are some other threads at stackoverflow that handle this message.

How to Remove HSQLDB Datasource in Tomee?

Apologies if I am posting a duplicate , if so please point me to original question.
I am running a tomee instance. I am configuring my data sources in context.xml and that are being pickup fine. But tomee also creates a HSQLDB datasource by default. And for few transaction it is being picked up and gives me error.
I would like to remove/ disable it from configuration so that it doesn't gives me those false error like:
user lacks privilege or object not found.
And I would be able to see actual issue with my application.
As Gimby said, you should define it in tomee.xml
If you are using eclipse check that your server locations is set to
"use Tomcat installation (take control...)"
and not
"use workspace metadata"
usefull links:
how-to-define-mysql-data-source-in-tomee
MySQL datasource in TomEE

Data directory in elastic search created inside project folder

I am using Java API (maven project) for elastic search. I configured elasticsearch.yml for path.data field as one of the directories. But when I run my code for indexing, in addition to the folder mentioned in config yml file, it also creates a /data/ directory inside the root of the project folder. I am unable to understand why it do so. Can someone please help.
In elasticsearch.yml
path.data: /data/servers/es.data
Thanks.
I also got this issue. In my case (I use Spring Boot) I think the issue is, I forgot to define a bean of org.elasticsearch.client.Client. So I think Spring generated a Client bean and 'made' an elasticsearch DB in my project folder.
Hope this helps someone! Cheers

Initial SessionFactory creation failed.java.lang.ClassFormatError

Error in Console:-
Initial SessionFactory creation failed.java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/transaction/SystemException
Hello
I am building a standalone Java Application with Main Method which connects to the database using Hibernate and writes to a file on C drive as well.
I have added all the libraries to the class path using Java Build Path configuration and user libraries. But I keep getting this error ...I have also added the javaee jar from the glassfish server libraries but that has also not solved the problem. I also have the jboss-transaction-api_1.1_spec-1.0.0.Final.Jar added to my class path.
Please advise as I am not using Maven as yet ???
Here are the jars in my build path-
-antlr
-c3p0
-commons-collections
-commons-logging
-commong-logging-api
-dom4j
-hibernate-c3p0
-hibernate-commons-annotation
-hibernate-core
-hibernate-entitymanager
-hibernate-envers
-hibernate-jpa
-javaee-api-6.0jar
-javaassist
-jboss-logging
-jboss-transaction-api
-jms
-log4j
-lucene-core
-MySQL-connector
-slf4j
-javaee.jar
Any help would be truly appreciated .. I am just lost on what is going on ?
I am sure you have 2 different versions for the same class. check your jars.

Categories