Foren

Help with message: Unsatisfied dependency of type - expected at least bean

John Malick, geändert vor 13 Jahren.

Help with message: Unsatisfied dependency of type - expected at least bean

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
I am new to LIFERAY and portlet programming. I am developing a portlet in Eclipse IDE using Springframe, Maven and Hiberate. I keep getting the following error message when I try to deploy my portlet.

19:52:20,086 ERROR [ContextLoader:215] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectTasksPortlet': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private edu.fccc.psf.projecttasks.services.TimeAcctService edu.fccc.psf.projecttasks.portlet.ProjectTasksPortlet.timeAcctService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeAcctService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private edu.fccc.psf.projecttasks.dao.ProjectsUsersDao edu.fccc.psf.projecttasks.services.TimeAcctService.projectsUsersDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [edu.fccc.psf.projecttasks.dao.ProjectsUsersDao] is defined: Unsatisfied dependency of type [interface edu.fccc.psf.projecttasks.dao.ProjectsUsersDao]: expected at least 1 matching bean

I have no idea how to fix this error. Can anyone help a confused programmer.

John Malick
215-728-2786
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
your projectTasksPortlet depends on TimeAcctService which depends on ProjectsUsersDao

The porlet can find the service but the service cannot find the dao so

If you are using xml configuration add your implementation of ProjectsUsersDao to the xml application context eg

<bean id="myProjectUsersDao" class="com.company.dao.impl.MyProjectsUsersDao" />


Or if you are using annotations, annotate your MyProjectsUsersDao with @Repository or @Component and make sure you are scanning the package your Dao implementation is in. Eg. configure <context:component-scan/> properly
John Malick, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Jelmer Kuperus,

First - THANK YOu for your reply. I appreciate any help I can get.

Second - Since I have been doing rookie (only doing JAVA for 3 months now), I don't always understand the terms so please be patient with me. Thank you for stating "your projectTasksPortlet depends on TimeAcctService which depends on ProjectsUsersDao. The porlet can find the service but the service cannot find the dao so.", that made sense to me. Yes, I am using several xml configuration files but I have more then one (someone set this up for me and send I need to let how to make it work). Which xml files do I add the line you gave me: pom.xml, web.xml, portlet.xml, portlet-servlet.xml,
projectTasks-portlet.xml or context.xml. Since I am new I am guesing it would be the portlet-servelt.xml file. Am I correct?

Yes, I am using annotations. What do you actually mean by "annotate your MyPorjectUsersDao" with @Repository or @Component" Do you by putting this annotation inside my DAO class?

Thank you again for your help! I really appreciate it!

John Malick
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
If you are defining your components in xml, then you should add it to an xml file that represents a spring applicationcontext

Spring application contexts start with <beans> and end with </beans>

In your case the following files are probably application contexts

portlet-servlet.xml,
projectTasks-portlet.xml
context.xml

You should probably add the line i mentioned to the xml file that also configures the service
(most likely context.xml)

If you cannot find the service defined in any of the application contexts, see if you can find something that looks like this in any of the files

<context:component-scan base-package="....." />

say your base package is com.company then spring will search for components annotated with @Component or one of the stereotypes and automatically add those components to the application context

So suppose your component-scan tag looks like this

<context:component-scan base-package="com.company" />

and your dao is com.company.dao.JpaProjectsUsersDao

then all you need to do is change JpaProjectsUsersDao to look like this

@Repository
public class JpaProjectsUsersDao implements ProjectsUsersDao {

}

and spring will automatically find the component and make it available to the service

However if your component-scan tag looks like this

<context:component-scan base-package="com.company.service" />

then you will have to add another component scan tag like this

<context:component-scan base-package="com.company.dao" />




It's all pretty basic stuff and spring is very well documented, read up on it in the excellent reference documentation if you get stuck

http://static.springsource.org/spring/docs/3.0.4.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html
John Malick, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Jelmer Kuperus,

First - Thank you again for your help. Your explanations are simple for me to understand. That I really appreciate.

Second - I am still having a problem and I was wondering if you don't mind continuing to help me.

I inserted your statement above in the portlet-servlet.xml file. I found the line "<context:component-scan base-package=" statement in there (Thank you for the clue). I did not try your @Repository statement yet. I just tried my portlet with the one change (I like taking baby steps so I can understand better what happens). It seems I still have the same error message but with something new.

Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/portlet-servlet.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name portlets is not bound in this Context.

Here is my portlet-servlet.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName">

<context:annotation-config />
<context:component-scan base-package="edu.fccc.psf.projecttasks" />

<bean id="projectsUsersDao" class="edu.fccc.psf.projecttasks.dao.ProjectsUsersHibernateDao" />

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
scope="singleton">
<property name="jndiName" value="java:comp/env/jdbc/portlets" />
<property name="resourceRef" value="false" />
</bean>


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>edu.fccc.psf.projecttasks.to</value>
<value>edu.fccc.psf.projecttasks.dao</value>
<value>edu.fccc.psf.projecttasks.portlet</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.jdbc.batch_versioned_data">
true
</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:annotation-driven proxy-target-class="true" />


<bean id="defaultExceptionHandler" class="org.springframework.web.portlet.handler.SimpleMappingExceptionResolver">
<property name="order" value="10"/>
<property name="defaultErrorView" value="error"/>
<property name="exceptionMappings" >
<props>
<prop key="javax.portlet.PortletSecurityException">unauthorized</prop>
<prop key="javax.portlet.UnavailableException">unavailable</prop>
</props>
</property>
</bean>
</beans>

Here is my context.xml file:
<Context>
antiJARLocking="true"
antiResourceLocking="true"
<Resource name="jdbc/myoracle"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@oracle.fccc.edu:1521:oracle"
username="ops$malick"
password="cowboys" />
</Context>

Here is my projectTasks-portlet.xml file:
?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<!-- This interceptor forwards the mapping request parameter from an ActionRequest to be used as a render parameter. -->
<bean class="org.springframework.web.portlet.handler.ParameterMappingInterceptor"/>
</property>
</bean>

<bean class="edu.fccc.psf.projecttasks.portlet.ProjectTasksPortlet" autowire="byName">
</bean>
</beans>

Does the "resource name" in my context.xml file need to be changed to "dataSource"? Should I just comment out my "dataSource" part of "portlet-servlet.xml" file and just use the @Repository statement you gave me. Sorry for being a pain but I really appreciate the help.

John Malick
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
the jndiName property on JndiObjectFactoryBean should match the name of the resource you configured

the bold text indicates what you need to change.

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
scope="singleton">
<property name="jndiName" value="java:comp/env/jdbc/myoracle" />
<property name="resourceRef" value="false" />
</bean>

oh and you might consider changing your password after having posted it to the internet ;)
John Malick, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Jelmer Kuperus,

Thank you again for your help. I truly appreciate it. I am beginning to understand somethings. Thank you.

Unfortunately this did not solve my problem. I still have the same error but with a slightly different message:

19:39:44,565 ERROR [ContextLoader:215] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectTasksPortlet': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private edu.fccc.psf.projecttasks.services.TimeAcctService
edu.fccc.psf.projecttasks.portlet.ProjectTasksPortlet.timeAcctService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeAcctService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private edu.fccc.psf.projecttasks.dao.ProjectsUsersDao edu.fccc.psf.projecttasks.services.TimeAcctService.projectsUsersDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectsUsersDao' defined in ServletContext resource [/WEB-INF/portlet-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Lorg/springframework/jdbc/support/lob/LobHandler;


The last part is new to me. I tried researching this on the web and I could not find much. What does "Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Lorg/springframework/jdbc/support/lob/LobHandler;" mean? Is this something that you can explain? It is frustrating that I can not get a simple DAO to be display into a portlet. If you need to see any other code, please let me know. I appreciate any new help you can give me. Thanks in advance.

John Malick

P.S. Thank you for pointing out my password. I guess I will have to pick a new sports team.
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
It means you do not have org.springframework.jdbc-x.x.x.RELEASE.jar on your classpath

Spring is divided into multiple modules. If you do not need spring's jdbc support you can leave out the jdbc classes and end up with a slightly slimmer war file

in your case however you need the jdbc module
John Malick, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Jelmer Kuperus,

Thank you so much. I feel like I beginning to understand things. The classpath modification helped but 2 very strange errors appeared (only errors).

20:37:56,341 ERROR [ContextLoader:220] Context initialization failed
java.lang.NoClassDefFoundError: org/springframework/core/SmartClassLoader

and

20:37:58,716 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for sample-projecttasks com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for sample-projecttasks

I never heard of SmartClassLoader? I presume you have. Sorry to ask again for your help.

Very much appreciated.

John Malick
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
Go to the spring site, download the distribution, unzip it
Go to http://cmarton.free.fr/jarsbrowser/
Click webstart me now
Point jarsbrowser to where you unzipped spring
Enter classname in the jarsbrowser searchbar

that will show you which jar contains the class
John Malick, geändert vor 13 Jahren.

RE: Help with message: Unsatisfied dependency of type - expected at least b

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Jelmer Kuperus,

Thanks again. Sorry I did not get back to you yesterday. It was 5pm (EST) and I had family business to take care of. I did as you said and I believe the jar file I was missing was called "log4j". I added that to my pom.xml file. Now I get a strange problem. Can you please help me with this?

17:12:00,514 ERROR [JDBCExceptionReporter:78] Cannot create JDBC driver of class '' for connect URL 'null'

I am reading about it and it does not make sense to me. Any help would be greatly appreciated. Thank you in advance.

John Malick