spring - Error creating bean.Injection of autowired dependencies failed. Could not autowire -
hello i´m newbie in spring mvc, i´m using @autowired don´t know solution. thx you. sorry english, i´m learning it. have 2 class empresa.java , ldiario.java. empresa.java works.
update updated following code have same error. app-config.xml
<!-- hibernate session factory --> <bean id="mysessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="mydatasource"/> <property name="packagestoscan" value="com.atorresbr.springapp.**"/>
and added bean.
<bean id="diariobean" class="com.atorresbr.springapp.bean.diariobean"/>
error
org.springframework.beans.factory.beancreationexception: error creating bean name 'diariobean': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private com.atorresbr.springapp.model.ldiario com.atorresbr.springapp.bean.diariobean.ldiario; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.atorresbr.springapp.model.ldiario] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)} @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:288) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1116) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:519) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)
diariobean.java
@managedbean(name="diariobean") @sessionscoped @component public class diariobean { @autowired private ldiario ldiario; @autowired private ldiario selectedldiario; public diariobean(){ } public ldiario getldiario() { return ldiario; } public void setldiario(ldiario ldiario) { this.ldiario = ldiario; } public ldiario getselectedldiario() { return selectedldiario; } public void setselectedldiario(ldiario selectedldiario) { this.selectedldiario = selectedldiario; } }
ldiario.java
import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.onetomany; import javax.persistence.onetoone; import javax.persistence.primarykeyjoincolumn; import javax.persistence.table; import java.io.serializable; import java.sql.blob; import java.util.date; @entity @table(name = "ldiario2014") public class ldiario implements serializable{ @id @column(name = "clave") @generatedvalue private integer clave; @manytoone @joincolumn (name = "empresa") private empresa empresa; @column(name = "asiento") private integer asiento; @column(name = "orden") private integer orden; @column(name = "fecha") private date fecha;
app-config.xml
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <!-- scans classpath of application @components @service @repository deploy beans --> <context:component-scan base-package="com.atorresbr.springapp" /> <!-- configures @controller programming model --> <mvc:annotation-driven /> <bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer" p:location="/web-inf/jdbc.properties" /> <bean id="diariobean" class="com.atorresbr.springapp.bean.diariobean"/> <!-- jdbc data source. assumed have mysql running on localhost port 3306 username root , blank password. change below if it's not case --> <bean id="mydatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close" p:driverclassname="${jdbc.driverclassname}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" p:validationquery="${jdbc.validationquery}" /> <!-- <bean id="mydatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://localhost:3306/pizzashop"/> <property name="username" value="root"/> <property name="password" value=""/> <property name="validationquery" value="select 1"/> </bean> --> <!-- hibernate session factory --> <bean id="mysessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="mydatasource"/> <property name="packagestoscan" value="com.atorresbr.springapp.**"/> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <!-- hibernate transaction manager --> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="mysessionfactory"/> </bean> <!-- activates annotation based transaction management --> <tx:annotation-driven transaction-manager="transactionmanager"/> </beans>
Comments
Post a Comment