Erro com Spring

2 respostas
Figuera

Estou tentando criar um DAO com Spring, mas não consigo passar por um erro (bem simples), ao chamar a linha:

Retorna o erro :

Exception in thread "main" java.lang.IllegalArgumentException: No SessionFactory specified

Parece a mim, que sou ainda iniciante em Spring que o erro está no arquivo configurador, então aqui segue o dito:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName">
			<value>...</value>
		</property>
		<property name="url">
			<value>
				...
                        </value>
		</property>
		<property name="username">
			<value>...</value>
		</property>
		<property name="password">
			<value>...</value>
		</property>
	</bean>
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQL5Dialect
				</prop>
			</props>
		</property>
	</bean>
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate.
    HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>
	<bean id="BaseDAO" class="gerBanco.Hibernate.DAO.ClsDAO">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>
</beans>

Já tentei de muita coisa, mas não consegui, tenho ainda a suspeita de ter salvo o applicationContext.xml em lugar errado, ele está agora salvo no pasta /bin .

2 Respostas

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

    <bean id="BaseDAO" class="gerBanco.Hibernate.DAO.ClsDAO">   
        <property name="sessionFactory">   
            <ref local="sessionFactory" />   
        </property>   
    </bean>   


    <bean id="daoTransacional"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="transactionManager">
        <ref local="transactionManager"/>
      </property>
      <property name="target">
        <ref local="BaseDAO"/>
      </property>
      <property name="transactionAttributes">
        <props>
          <prop key="delete*">
            PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED
          </prop>
          <prop key="save*">
            PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED
          </prop>
          <prop key="update*">
            PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED
          </prop>
          <prop key="get*">
            PROPAGATION_SUPPORTS, readOnly
          </prop>
          <prop key="list*">
            PROPAGATION_SUPPORTS, readOnly
          </prop>
        </props>
      </property>
    </bean>
Figuera

Bom, eu sei que demorei um pouco, parei de mexer com o Spring por um tempo…

Eu tentei o que disseram acima mas não funcionou.

Criado 1 de janeiro de 2008
Ultima resposta 13 de jan. de 2008
Respostas 2
Participantes 2