Hello i m using oracle database but i get some errors , with spring boot :
the erors 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
my application properties is :
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.datasource.url= jdbc:oracle:thin:#localhost:1521:XE
spring.datasource.username=Sys
spring.datasource.password=admin
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.jpa.hibernate.ddl-auto=create
server.port = 8080
spring.jpa.show-sql=true
spring.servlet.multipart.max-file-size=-1
Which Java version you are using? Can you check if you have added dependencies in your build file?
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
Reference Link : https://www.baeldung.com/java-9-jaxbexception
Related
When running the Spring Boot app, I have these error messages:
"Caused by: java.lang.RuntimeException: Driver
com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl,
mysql://localhost:3306"
and
"Caused by: org.springframework.beans.BeanInstantiationException:
Failed to instantiate
[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]:
Factory method 'entityManagerFactory' threw exception; nested
exception is java.lang.RuntimeException: Driver
com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl,
mysql://localhost:3306".
enter image description here
I have added the dependencies in the POM file:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
<scope>runtime</scope>
</dependency>
Java version is:
<properties>
<java.version>17</java.version>
</properties>
Just from a quick look at it, it looks like your jdbc connector address isn't complete. You are missing a db there, something like
jdbc:mysql://localhost:3306/ReallyNiceDb
In MySQL, you will need to create a database, in this case, called ReallyNiceDb. Then, to this database, you will need to allow your user to interact with that database.
More info can be found here:
https://dev.mysql.com/doc/refman/8.0/en/creating-database.html
Im developing spring boot Rest API, application,
In my VS code application is running without any runtime errors and working with postman too,
VS code runtime output
enter image description here
however, when i export the JAR file via VS code, and try to run cmd, that file pop up run time error,
ERROR
Blockquote
enter image description here
Blockquote
Error Msg in cmd
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
My POM XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
application.properties
## Server Properties
server.port= 8083
server.servlet.context-path= /TEST-API
spring.datasource.url= jdbc:mysql://localhost:3306/TEST?useSSL=false&useLegacyDatetimeCode=false&zerodatetimebehavior=Converttonull
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username= root
spring.datasource.password= 1234
spring.datasource.testWhileIdle = true
spring.datasource.timeBetweenEvictionRunsMillis = 60000
spring.datasource.validationQuery = SELECT 1
Could you please help me on this?
Option 1
Try use
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
instead of
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
in your properties file, if you are using mysql version < 8
Option 2
Check if your driver of mysql (JAR file) was included in the library of WAR --> WEB-INF/lib.
Option 3
If you are not fix it yet, and you have other database in your machine like a postgres:
change this connection to this another database.
test inside of your editor/ide
export to war
if the problem happens the same way, you can be right that your export process is the problem. So try use the plugin of maven to generate the war: https://maven.apache.org/plugins/maven-war-plugin/usage.html
Thanks for your support
one of my friends help me to fix the issue
what they did is,
delete mvnw file from the project path.
Then paste apache-maven-3.6.0 in to C driver and then
did the maven install and package the project in vs code.
After that project jar generated.
My spring boot test is throwing the below error during maven build.
"level":"ERROR","logger":"com.zaxxer.hikari.HikariConfig","msg":"HikariPool-1 - jdbcUrl is required with driverClassName."
Stacktrace:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in class path resource
[com/pit/SchedulerConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: jdbcUrl is requir
ed with driverClassName.
Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
The method that throws an error in my MyApplicationTest.java
#SpringBootTest
#EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
#EnableConfigurationProperties(value = MyConfig.class)
class MyApplicationTest {
#Test
void contextLoads() {
assertNotNull(myController);
}
}
My pom has these dependencies in classpath.
spring-boot-starter-web
spring-boot-starter-test
spring-integration-sftp
postgresql
junit
quartz-scheduler
My Datasource bean is configured as below
#Configuration
public class MyDataSourceCfg {
private DataSource appDataSource() {
return DataSourceBuilder.create()
.driverClassName("org.postgresql.Driver")
.url(env.getProperty("url") // values are set from Environment
.username(env.getProperty("user"))
.password(env.getProperty("password")
.build();
}
}
Please tell me what is happening and how I avoid this error. I read about configuring Datasource in different way in case you have multiple database but I just have one postgres database. Please share your thoughts.
Considering that you have all relevant dependencies.
as Connect to PostgreSQL Database with Spring Data JPA such as :-
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
and in application.properties file:
spring.datasource.url=jdbc:postgresql://localhost:5432/dev
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL81Dialect
With SpringBoot's powerful autoconfiguration, you don't need to explicitly create a DataSource bean and if in case you want, use these properties values.
I was working on a Spring boot research project which connects to a mariadb database using Hibernate, in Java 1.8. Recently I have upgrated to Java version to 13. Now following error occures when my application try to use database connection.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sqlDBServiceHibernateImpl' defined in file [F:\RND\negorate-inventory\negorate-data-service\target\classes\it\codegen\rnd\negorate\dataservice\services\SqlDBServiceHibernateImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [it.codegen.rnd.negorate.dataservice.services.SqlDBServiceHibernateImpl]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.hibernateConnectorProvider' defined in file [F:\RND\negorate-inventory\negorate-data-service\target\classes\it\codegen\rnd\negorate\dataservice\connectors\HibernateConnectorProvider.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [it.codegen.rnd.negorate.dataservice.connectors.HibernateConnectorProvider]: Constructor threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:312)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:293)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:359)
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:390)
at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:184)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:356)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at it.codegen.rnd.negorate.dataservice.services.SqlDBServiceHibernateImpl$$EnhancerBySpringCGLIB$$a8a80337.getSessionTokenByKey(<generated>)
Hibernate configurations in application.properties file.
hibernate.connection-url=jdbc:mariadb://192.168.2.144:3306/negorate_qa
hibernate.driver-class=org.mariadb.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MariaDB103Dialect
hibernate.hbm2ddl-auto=validate
Maven dependencies in pom.xml file.
<dependency>
<groupId>it.codegen.rnd</groupId>
<artifactId>hibernate-connector</artifactId>
<version>5.2.1.16</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.4.5.Final</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.2</version>
</dependency>
hibernate-connector is a company specific dependency which is based on hibernate-core 5.4.5.Final version.
Database specification,
mysql> status;
--------------
mysql Ver 8.0.20 for Win64 on x86_64 (MySQL Community Server - GPL)
Connection id: 1930851
Current database: negorate_qa
Current user: admin#172.16.4.60
SSL: Not in use
Using delimiter: ;
Server version: 5.5.5-10.3.9-MariaDB-1:10.3.9+maria~trusty-log mariadb.org binary distribution
Protocol version: 10
Connection: 192.168.2.144 via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: cp850
Conn. characterset: cp850
TCP port: 3306
Binary data as: Hexadecimal
Uptime: 63 days 21 hours 26 min 27 sec
I need to know what exactly happned after the Java migration and how to fix this issues.
Thank you.
( I tried severel similar questions, but none of them solved this scenario. )
I am trying to create a web service application using informix RDBMS and Spring boot.
When I declare ddl-auto = create it works perfectly but when I change it to update or none I get the error. My informix version is Version 9.40.UC8.
spring.datasource.url=jdbc:informix-sqli://*.*.*.*:*/testechange:INFORMIXSERVER=server
spring.datasource.username=
spring.datasource.password=
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
spring.datasource.driver-class-name=com.informix.jdbc.IfxDriver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.InformixDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.hibernate.ddl-auto=update
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
server.port=8182
#Entity
#Table(name ="todos")
public class Todo {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id ;
#Column
private String name ;
}
<dependencies>
<!-- https://mvnrepository.com/artifact/com.ibm.informix/jdbc -->
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>jdbc</artifactId>
<version>4.10.6.20151104</version>
</dependency>
</dependencies>
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.GenericJDBCException: Error accessing tables metadata
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Error accessing tables metadata
Caused by: org.hibernate.exception.GenericJDBCException: Error accessing tables metadata
Caused by: java.sql.SQLException: Routine (get_data_type) can not be resolved.*
When you use update you are indicating that the connection you will get with spring will be dynamic to which you can receive changes as you make them.