Trying to connect to Postgres DB, context params are as below:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/****" />
<property name="username" value="****" />
<property name="password" value="****" />
</bean>
Getting exception on context loading:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource' defined in ServletContext
resource [/WEB-INF/ApplicationContext.xml]: Error setting property
values; nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are: PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property
'driverClassName' threw exception; nested exception is
java.lang.IllegalStateException: Could not load JDBC driver class
[org.postgresql.Driver]
I have the postgres driver in the LIB of the project, as I can check the class file org.postgresql.Driver. The Class.forName also gives a positive result for the driver class.
I have tried all versions of postgres drivers, but still this isn't going through.
Make sure the lib gets copied to the packaging correctly and that that directory is in the classpath.
I was able to resolve the issue , When I added the Postgres DB Jar to the WEBINF/Lib the bean was getting created , Some how it was not picking the jar from the JavaResource/Lib as i was doing this before .
The problem is a particular case which is not answered in most of the places well and just checking the classpath wont be a correct answer to this query.
Related
So I have a project I want to start work with. The senior developer sent me a zip package of the project and database.sql file for initializing the local database for me to just launch the project. But we are facing the error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/spring-database.xml]: 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
All entities are exactly the same as in the local database. I have changed the XML file config to match my password and URL. Spend 2 days trying to run the project. Will appreciate any help. Please feel free to ask any questions.
<!-- Configure the entity manager factory bean -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<!-- Set JPA properties -->
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.ProgressDialect</prop>
</props>
</property>
<property name="packagesToScan" value="nl.impressie.grazer.hibernate" />
</bean>
Sounds like hibernate is failing to initialize due to a failure to connect to the DB.
Are you sure you have a Postgresql DB running? Is Spring configured correctly to interface with that DB? (i.e. is the host, port, databaseschema, username and password set?)
If this is a new project, you shouldn't be using any of this XML configuration at all. Instead, create a template project at https://start.spring.io that includes the JPA starter, set your spring.datasource.url, and be running in 2 minutes.
I have configured the following beans in my application context:
<bean id="bindConnectionPool" parent="abstractConnectionPool"
p:connectionFactory-ref="bindConnectionFactory" />
<bean id="bindConnectionFactory"
class="org.ldaptive.DefaultConnectionFactory"
p:connectionConfig-ref="bindConnectionConfig" />
<bean id="bindConnectionConfig" parent="abstractConnectionConfig" />
<bean id="abstractConnectionConfig" abstract="true"
class="org.ldaptive.ConnectionConfig"
p:ldapUrl="ldaps://myldap.example.com:636"
p:connectTimeout="3000"
p:useStartTLS="true"
p:sslConfig-ref="sslConfig" />
<!-- EDIT/UPDATE: -->
<bean id="sslConfig" class="org.ldaptive.ssl.SslConfig">
<property name="credentialConfig">
<bean class="org.ldaptive.ssl.X509CredentialConfig"
p:trustCertificates="mycert" />
</property>
</bean>
When I deploy the WAR to Tomcat I get the following exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name ‘bindConnectionPool’ defined in ServletContext resource
[/WEB-INF/deployerConfigContext.xml]: Invocation of init method failed; nested exception
is java.lang.IllegalArgumentException: path must start with either classpath: or file:
What do I need to change the LDAPS-based URL to? Neither file: nor classpath: make sense here...thoughts?
Or, is ldapUrl a red herring, and is there some other path defined on this bindConnectionPool bean that isn't configured right? Oh, and obviously, can't post the LDAP server's actual name for security reasons (myldap.example.com is a different value).
I have the following configuration in my spring bean.xml, when I run i get the ERROR: as mentioned below. I could not understand what the below configuration tag and use of it. where to specify the config.file
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:#{ systemProperties['config.file']}</value>
</property>
Error:
Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException:
Are you remembering to pass the value -Dconfig.file=c:/blah/blah.config.props
I got the following error :
Error creating bean with name
'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'
defined in class path resource [jpaDaoContext.xml]: Initialization of
bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'vodEntityManagerFactory' defined in class
path resource [jpaDaoContext.xml]: Invocation of init method failed;
nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: vodPersistenceUnit] class or package not found
I had a look on Google and I was told to choose transaction-type=RESOURCE_LOCAL but the settings were already that way. What is wrong with these settings :
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<!-- transaction-type is RESOURCE_LOCAL or JTA -->
<persistence-unit name="vodPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<class>mypackage.persistent.HistoriqueAction</class>
<class>mypackage.persistent.ParametresTechniques</class>
<class>mypackage.persistent.TicketType</class>
<class>mypackage.persistent.TransactionType</class>
<class>mypackage.persistent.StatutSession</class>
<class>mypackage.persistent.Statistique</class>
<class>mypackage.persistent.StatUser</class>
<!-- Avoid to scan *.class and *.hbm.xml -->
<exclude-unlisted-classes />
</persistence-unit>
</persistence>
Regards
I fixed the issue. I had to comment these three lines in the file "persistence.xml" :
<!--class>mypackage.persistent.TicketType</class>
<class>mypackage.persistent.TransactionType</class>
<class>mypackage.persistent.StatutSession</class-->
For the moment i have no idea why it fixes the issue. It is really hard to debug this spring file.
If you had to comment out the "class" elements, it is likely that one of those classes is either not defined, or is not available in the classpath.
I faced the same exact error, and it was resolved once the fully qualified names were all correct. Ideally, Hibernate should tell you what class is not found, but sadly it does not do it in this case.
You you haven't done that, put <property name="persistenceUnitName" value="vodPersistenceUnit" /> in your jpaDaoContext.xml as property of your entityManagerFactory bean definition like:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="vodPersistenceUnit" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">...</property>
</bean>
I was running into this exception when trying to run a Spring Boot application in WebLogic 12.1.3 In the dependency tree I found out spring-tx was being included from one of the common project libraries. Our particular app only calls web service so there is no need for database access. So in the library dependency I added:
<exclusions><exclusion> <groupId>org.springframework</groupId><artifactId>spring-tx</artifactId></exclusion></exclusions>
I was trying to do some basic database operations. I'm using STS 3.2.0, Apache Tomcat 7.
My dispatcher-servlet.xml includes:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mydb" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
Apache Tomcat fails miserably with thousands of exceptions, starting with this one :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
EDIT 1: I also downloaded 3.0.3.RELEASE version of the jar, and its still the same.
FINAL EDIT It seems, you should add your external jar files manually to your deployment directory as well (well if you don't use any extension that'd do that for you)
Try to add to POM.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
I think you should import selected jdbc jar into web app library.
if none of the above solution doesn't work, then manually add spring-jdbc jar file to webapp/WEB-INF/lib.