Initialization of bean failed; ConversionNotSupportedException - java

I have a higher hierarchy context, which on server startup (tomcat) gets the following bean:
<bean id="org.sakaiproject.rubrics.api.rubric.RubricsService" class="org.sakaiproject.rubrics.impl.RubricsServiceImpl"
init-method="init"
singleton="true">
<property name="rubricsLogic" ref="org.sakaiproject.rubrics.logic.RURubricLogic" />
<property name="externalLogic" ref="org.sakaiproject.rubrics.api.rubric.ExternalLogic" />
</bean>
That bean's class ('RubricsServiceImpl'), implements an API interface called RubricsService ... so far so good. This initializes OK.
Down the hierarchy, when webapps are being deployed, on of these references this bean in applicationContext.xml :
<bean id="org.sakaiproject.rubrics.tool.RubricsTool" class="org.sakaiproject.rubrics.tool.RubricsTool">
<property name="rubricsService" ref="org.sakaiproject.rubrics.api.rubric.RubricsService" />
</bean>
While deploying the app, the following exception is thrown:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.rubrics.tool.RubricsTool' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.sakaiproject.rubrics.impl.RubricsServiceImpl' to required type 'org.sakaiproject.rubrics.api.rubric.RubricsService' for property 'rubricsService'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [org.sakaiproject.rubrics.impl.RubricsServiceImpl] to required type [org.sakaiproject.rubrics.api.rubric.RubricsService] for property 'rubricsService':
no matching editors or conversion strategy found
All the poms contain all the dependencies where they belong so no package starves from definitions or anything. I am clueless.
Could this be a Class Loader issue?
The following is my applications structure:

Ok... it was a classloader problem. The webapp's classloader was colliding with the container-level one, hence no casting could be done.
All the API .jars are deployed to tomcat's shared/lib directory for all apps to be able to access them. This is done by setting in the pom of the API module (of the webapp) :
<properties>
<deploy.target>shared</deploy.target>
</properties>
Now, based on the hierarchy of the webapp above, rubrics has a base pom.xml for the webapp, and in this, it is necessary to define the property so all the children poms of its modules, shared this dependencies. By markind in the base pom.xml of the webapp the following:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.sakaiproject.rubrics</groupId>
<artifactId>rubrics-api</artifactId>
<version>10.4</version>
<scope>provided</scope> <!-- from the CONTAINER -->
</dependency>
<dependency>
<groupId>org.sakaiproject.rubrics</groupId>
<artifactId>rubrics-impl</artifactId>
<version>10.4</version>
</dependency>
</dependencies>
</dependencyManagement>
Then, we just set the dependency if we need it with no .jar defined for that classloader, but to be provided by the container later on.
This was my interpretation after solving the issue. Please feel free to correct/add/enrich.

Related

NoSuchBeanDefinitionException:No qualifying bean of type [weblogic.messaging.saf.internal.SAFServerService] for Weblogic (12.2.1.3.0)

I am getting below message while deploying spring MVC application into Weblogic (12.2.1.3.0)
NoSuchBeanDefinitionException:No qualifying bean of type [weblogic.messaging.saf.internal.SAFServerService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject(), #javax.inject.Named(value=SAFServerService)
Please help.
Spring can automatically detect classes and register beans. see details at Classpath scanning and managed components.
Adding inside to skip the concerned Java packages related to com.oracle and IBM, which are not used or referenced directly by the application, should prevent the errors from happening during deployment.
In the involved war file, the application has used Spring application-context.xml at /WEB-INF/classes/../../ for allowing the search for classes annotated with #Component, #Repository, #Service, and #Controller in Spring classpath.
Example of the application-context.xml :-
<context:component-scan base-package="com,test" scoped-proxy="no">
<context:exclude-filter type="regex" expression="com\.oracle.*" />
<context:exclude-filter type="regex" expression="com\.ibm.*" />
</context:component-scan>

Java8 upgrade done from Java6 and Tomcat7.0 to Tomcat8.0 >bean creation Exception

I'm having issue while upgrading JAVA8 from Java6 and Tomcat7.0 to Tomcat8.0. Before I'm having Spring source suite tool development tool. hibernate3 jar file is used I'm having below issue.
Please let me know which hibernate jar files it will support and other jar files?
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'desecn' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean
'itracProps' while setting bean property 'icProps';
nested exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'itracProps' defined in ServletContext
resource [/WEB-INF/applicationContext.xml]: Invocation of init method
failed;
nested exception is java.lang.NullPointerException.
WEB-INF/Application-context.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans
PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- COMMON CLASS -->
<bean id="desecn" class="com.appfoundation.itrac3.misc.DesEncrypter">
<property name="icProps" ref="icProps" />
</bean>
<bean id="utility" class="com.appfoundation.itrac3.misc.Utility">
<property name="icProps" ref="icProps"/>
<property name="desecn" ref="desecn"/>
</bean>
<!-- Precept Migration - init method is placed to get Servlet Context from Spring Web Application Context -->
<bean id="icProps" class="com.appfoundation.itrac3.misc.ItProperties" init-method="loadProperties"/>

Spring MVC project cannot use Hibernate

I want to build a Spring MVC project with Hibernate.
The IDE I used is Eclipse 4.4.2(Luna) and I installed the plugin Spring Tool Suite (STS) for Eclipse Luna (4.4).
The project I create is Spring project > Spring MVC Project.
Here is the External Jars I add :
antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.9.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
mysql-connector-java-5.0.8-bin.jar
Then, I add the detail of my database into /src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml :
<beans:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url" value="jdbc:mysql://192.168.1.43/MyDatabase" />
<beans:property name="username" value="testUser" />
<beans:property name="password" value="thePassOfTheUser" />
</beans:bean>
However, it shows the error message :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
org.springframework.jdbc.datasource.AbstractDataSource.<init>(AbstractDataSource.java:37)
org.springframework.jdbc.datasource.DriverManagerDataSource.<init>(DriverManagerDataSource.java:87)
Since I cannot fix it, I tried write hibernate.cfg.xml, but I have no idea where the file should be put.
I want to know how to set the bean to let my project can use Hibernate and how to use transitional way of hibernate (hibernate.cfg.xml) in the MVC project.
May 19th added
I found the solution.
It is because maven didn't load hibernate. Therefore after adding the following code into pom.xml it can work:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager‌​</artifactId>
<version>3.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.‌​hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.0.Final</v‌​ersion>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</‌​artifactId>
<version>1.3.156</version>
</dependency>
<dependency>
<groupId>org.spring‌​framework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.0.6.RELEASE</ve‌​rsion>
</dependency>
Your error is related to missing library in classpath. Which is:
org.apache.commons.logging
Try to fix that first then tell if problem still occurs.
The stacktrace says that you're missing LogFactory which is part of Apache Commons Logging. I don't see it included in your external jars.
For the transitional way of hibernate create hibernate.cfg.xml configuration file and place it in the root of your application's classpath.
The XML configuration file must conform to the Hibernate 3 Configuration DTD, which is available from http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd.
Here is a tutorial on it.

Spring 4 config problems afer migration from v3 (util:properties location is no longer evaluating spEL)

I had a working spring 3 application which after migration to 4.1.0.RELEASE started to cause problems. Configuration below stopped working:
<jee:jndi-lookup id="dit_properties_path" jndi-name="dit_properties_path" resource-ref="true" />
<util:properties id="systemProperties" location="classpath:system.properties" />
<util:properties id="serverProperties" location="#{dit_properties_path}"/>
After migration it seems that spring is not able to resolve spEL #{dit_properties_path}, and is showing following error:
[PropertiesFactoryBean] [INFO]: Loading properties file from ServletContext resource [/#{dit_properties_path}]
[...]is java.io.FileNotFoundException: Could not open ServletContext resource [/#{dit_properties_path}]
Jndi resource is of type java.lang.String and points to local FS (C:\someFile.properties).
Here's tomcat definition of the resource /server and context/:
<Environment name="dit_properties_path" value="file:C:\someFile.properties"
type="java.lang.String" override="true"/>
and
<ResourceLink name="dit_properties_path"
type="java.lang.String"
global="dit_properties_path" />
Do anyone have any idea how to resolve this issue?
I have several property files in my app which are often accessed by #{propertyFileId['key']} and they have to be loaded dynamically from jndi resource path.
Change from :
<util:properties id="serverProperties" location="#{dit_properties_path}"/>
to:
<util:properties id="serverProperties" location="${dit_properties_path}"/>
solved the problem. Still, can't figure out why given expression doesn't work with hash sign.

Spring JDBC : unable to get dataSource

I have a spring XML config file called appConfig.xml which contains a datasource bean and another JDBCtemplate to which datasource is passed as an argument:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test"/>
</bean>
<bean id="JDBCTemplate" class="com.myprojects.JDBCTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
I get an error :
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JDBCTemplate' defined in file [appConfig.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required
From what I see from this error, it is not able to pass dataSource to JDBCTemplate. The logs also says:
Loaded JDBC driver: com.mysql.jdbc.Driver
I have all dependencies mentioned in pom.xml and I verified that necessary jars for spring are loaded and mysql jdbc connector is also loaded. Any clues on what the issue may be?
I tried a different project where I manually added all spring dependencies and mysql jdbc connector as part of library. It worked fine there. But while trying to include dependencies via pom.xml, I'm facing this issue. So I'm assuming this is to do with some dependency not being pulled in or something. But unable to figure out which one from the error.
It thinks your class JDBCTemplate does not have a property named dataSource
Perhaps you don't have a public method setDataSource() that has a single argument of the right type.
Perhaps it is private.
Perhaps it is spelled wrong.

Categories

Resources