I have a Spring application, which is configured for multiple Persistent units.
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list value-type="java.lang.String">
<value>classpath*:META-INF/*-persistence.xml</value>
</list>
</property>
<property name="dataSources">
<map>
<entry key="dataSource" value-ref="dataSource" />
</map>
</property>
<property name="defaultDataSource" ref="dataSource" />
<property name="defaultPersistenceUnitName" value="pm-model" />
</bean>
However, I'm getting an error on startup saying that one of the persistent units is not able to load. I also called out in the code above to list all the persistence.xml files, but still getting the same error.
ERROR 2017-08-10 15:33:44,882 [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bService': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com-model' is defined
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
If anyone has any suggestions, I'm all ears. Thanks in advance.
Related
I am trying to set the proxy to spring rest template bean based on the property, I tried below configuration,
<bean id="forwardProxy" class="java.net.Proxy">
<constructor-arg>
<util:constant static-field="java.net.Proxy.Type.HTTP"/>
</constructor-arg>
<constructor-arg>
<bean class="java.net.InetSocketAddress">
<constructor-arg value="${forward.proxy.host}"/>
<constructor-arg value="${forward.proxy.port}"/>
</bean>
</constructor-arg>
</bean>
<util:constant id="noProxy" static-field="java.net.Proxy.NO_PROXY" />
<bean id="myRestTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg>
<bean class="org.springframework.http.client.SimpleClientHttpRequestFactory">
<property name="connectTimeout" value="5000"/>
<property name="readTimeout" value="5000"/>
<property name="proxy" ref="#{ ${aem.enableProxy}==true ? forwardProxy : noProxy }"/>
</bean>
</constructor-arg>
</bean>
but I am getting below error saying No bean named 'DIRECT' available
Caused by (repeated) ... : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRestTemplate' defined in class path resource [environment/application.xml]:
Cannot create inner bean 'org.springframework.http.client.SimpleClientHttpRequestFactory#1177bca' of type [org.springframework.http.client.SimpleClientHttpRequestFactory] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.client.SimpleClientHttpRequestFactory#1177bca' defined in class path resource [environment/application.xml]:
Cannot resolve reference to bean '#{ false==true ? forwardProxy : noProxy }' while setting bean property 'proxy'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'DIRECT' available
Proxy.Type.DIRECT is a enum, not sure how to create a bean for that. Is it possible to achieve what I am doing without creating a factory beans option.
Using spring version: 4.3.8
Spring config in xml
<jee:jndi-lookup id="datas1" expected-type="javax.sql.DataSource"
jndi-name="java:/jndi1" />
<jee:jndi-lookup id="datas2" expected-type="javax.sql.DataSource"
jndi-name="java:/jndi2" />
<bean id="EntityM"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datas1" />
<property name="packagesToScan" value="package.persistence.entity" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.Oracle12cDialect" />
</bean>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="EntityM" />
</bean>
The Excpetion is:
Context initialization failed: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSessionJdbcOperations' defined in class path resource [org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfiguration.class]: Unsatisfied dependency expressed through method 'springSessionJdbcOperations' parameter 0: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: datas1,datas2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: datas1,jndi2.
I can not have two datasources configured, The first datasource is to the entityManagar and second datasource is to call stored procedure.
The JdbcSessionConfiguration expects a bean of type 'DataSource' with name 'dataSource'.
If this cannot be found, spring tries to use a bean of type 'DataSource', ignoring the name. Because there are two beans of this type, the exception is thrown.
Solution :
Rename the DataSource bean, that you want to use with the EntityManager from
'datas1' to 'dataSource'.
Spring should than be able to create JdbcSessionConfiguration and you can use the 'datas2' for whatever you need.
I am migrating from Hibernate 3/Spring 3 to Hibernate 5/Spring 4 and am receiving this error:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'sessionFactory-ETL' defined in class path resource
[config/context-hm.xml]: Error setting property values; nested
exception is org.springframework.beans.NotWritablePropertyException: Invalid
property 'eL' of bean class
[org.springframework.orm.hibernate5.LocalSessionFactoryBean]: Bean property
'eventListeners' is not writable or has an invalid setter method. Does the
parameter type of the setter match the return type of the getter?
Here is part of the config file:
<bean name="hibernateEventListeners" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="pre-update" value-ref="pup" />
<entry key="save-update" value-ref="xSaS" />
<entry key="post-insert" value-ref="xIS" />
<entry key="merge" value-ref="xML" />
<entry key="pre-delete" value-ref="eRUL" />
</map>
</property>
</bean>
<bean id="sessionFactory-ETL"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="eventListeners" ref="hibernateEventListeners" />
Can anyone shed some light on this? I'm not sure if I need to change the type of the hibernateEventListeners to something other than a MapFactoryBean.
Can anyone provide me the details as how to implement the "JobNameToJobRestartRequestAdapter" Class API for restarting the failed job by providing the name of the job that needs to be executed.
I created the context-xml file
<int:channel id="job-launches" />
<int:channel id="job-restarts" />
<int:service-activator id="restartJobClassProperties" input-channel="job-restarts" output-channel="job-requests">
<bean class="org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter">
<property name="jobLocator" ref="jobRegistry" />
<property name="jobExplorer" ref="jobExplorer" />
</bean>
</int:service-activator>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.JobLocator">
<property name="name" value="JobNameGoesHere" />
</bean>
<bean id="jobExplorer" class="org.springframework.batch.core.explore.JobExplorer" />
While executing the main class which is reading this context.xml file I am getting below error:
Error creating bean with name
'org.springframework.integration.config.ServiceActivatorFactoryBean#0':
Cannot create inner bean
'org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0'
of type
[org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter]
while setting bean property 'targetObject'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.batch.admin.integration.JobNameToJobRestartRequestAdapter#0'
defined in class path resource
[META-INF/spring/restart-job-context.xml]: Cannot resolve reference to
bean 'jobRegistry' while setting bean property 'jobLocator'; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jobRegistry' defined in class path
resource [META-INF/spring/restart-job-context.xml]: Instantiation of
bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[org.springframework.batch.core.configuration.JobLocator]: Specified
class is an interface
I want to implement the functionality for defining the batch job name which I would like to restart and the properties can be extracted from the jobexplorer based on the last executed step.
JobLocator is an interface. You can't define a bean that is just an interface. I think you want to use a JobRegistry. Below is what Spring Batch Admin uses:
<bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
<property name="applicationContextFactories">
<bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
<property name="resources" value="classpath*:/META-INF/spring/batch/jobs/*.xml" />
</bean>
</property>
<property name="jobLoader">
<bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
</property>
</bean>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
The jobRegistry bean is a registry for the jobs to be looked up from (it does implement JobLocator. The jobLoader registers job definitions with the registry.
Im getting the following issue when trying to create session factory.
javax.servlet.ServletException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'factory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'factory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
root cause
java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
Spring.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" default-autowire="byName">
<!-- <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>-->
<bean id="userDao"
class="com.virtusa.ideas.util.HibernateUserDAO">
<property name="factory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/virtusa/ideas/entity/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<!-- <props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>-->
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/ideas" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
</beans>
Can anyone help please?
You are missing cglib jar which is required by hibernate for code-generation.