mercury841
19-12-2007, 09:53
Ragazzi sto provando a sviluppare la mia prima applicazione in Spring e Ibatis. Quello che voglio fare è una semplice applicazione che faccia un inserimento in una tabella di un database. Adesso posto i file xml di configurazione e poi vi dico qual'è il problema.
spring-ibatis.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>sun.jdbc.odbc.JdbcOdbcDriver</value>
</property>
<property name="url">
<value>jdbc:odbc:Univ</value></property>
<property name="username"><value></value></property>
<property name="password"><value></value></property>
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>sql-map-config.xml</value>
</property>
</bean>
<bean id="studentDao"
class="ibatis.StudenteDaoImpl">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="sqlMapClient"><ref local="sqlMapClient"/></property>
</bean>
</beans>
sql-map-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE SqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sql-map-config>
<sql-map resource="Studente.xml"/>
</sql-map-config>
Studente.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap>
<typeAlias type = "ibatis.entity.Studente" alias = "studente"/>
<resultMap class = "studente" id = "result">
<result property = "matricola" column = "mat"/>
<result property = "nome" column = "nome"/>
<result property = "cognome" column = "cognome"/>
<result property = "corso" column = "corso"/>
</resultMap>
<select id = "selectAllStudents" resultMap = "result">
select * from studente
</select>
<select id = "selectStudentsByMat" resultMap = "result" parameterClass = "string">
select * from studente where mat = #value#
</select>
<insert id = "insertStudent" parameterClass="studente">
insert into Jsr (mat, nome, cognome, corso) values (#matricola#, #nome#, #cognome#, #corso#)
</insert>
<delete id = "deleteStudent" parameterClass="string">
delete from studente where mat = #value#
</delete>
<update id = "updateStudent" parameterClass="studente">
update studente set nome = #nome#, cognome = #cognome#, corso = #corso#
where mat = #matricola#
</update>
</sqlMap>
Quando provo ad esguire l'applicazione ottengo questo errore nel file spring-ibatis.xml:
"java.io.FileNotFoundException: class path resource [sql-map-config.xml] cannot be opened because it does not exist".
Com'è possibile? Entrambi i file spring-ibatis.xml e sql-map-config.xml si trovano nella stessa cartella all'interno del progetto (nomeprogetto/config).
Grazie per l'aiuto. CIao
spring-ibatis.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>sun.jdbc.odbc.JdbcOdbcDriver</value>
</property>
<property name="url">
<value>jdbc:odbc:Univ</value></property>
<property name="username"><value></value></property>
<property name="password"><value></value></property>
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>sql-map-config.xml</value>
</property>
</bean>
<bean id="studentDao"
class="ibatis.StudenteDaoImpl">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="sqlMapClient"><ref local="sqlMapClient"/></property>
</bean>
</beans>
sql-map-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE SqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sql-map-config>
<sql-map resource="Studente.xml"/>
</sql-map-config>
Studente.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap>
<typeAlias type = "ibatis.entity.Studente" alias = "studente"/>
<resultMap class = "studente" id = "result">
<result property = "matricola" column = "mat"/>
<result property = "nome" column = "nome"/>
<result property = "cognome" column = "cognome"/>
<result property = "corso" column = "corso"/>
</resultMap>
<select id = "selectAllStudents" resultMap = "result">
select * from studente
</select>
<select id = "selectStudentsByMat" resultMap = "result" parameterClass = "string">
select * from studente where mat = #value#
</select>
<insert id = "insertStudent" parameterClass="studente">
insert into Jsr (mat, nome, cognome, corso) values (#matricola#, #nome#, #cognome#, #corso#)
</insert>
<delete id = "deleteStudent" parameterClass="string">
delete from studente where mat = #value#
</delete>
<update id = "updateStudent" parameterClass="studente">
update studente set nome = #nome#, cognome = #cognome#, corso = #corso#
where mat = #matricola#
</update>
</sqlMap>
Quando provo ad esguire l'applicazione ottengo questo errore nel file spring-ibatis.xml:
"java.io.FileNotFoundException: class path resource [sql-map-config.xml] cannot be opened because it does not exist".
Com'è possibile? Entrambi i file spring-ibatis.xml e sql-map-config.xml si trovano nella stessa cartella all'interno del progetto (nomeprogetto/config).
Grazie per l'aiuto. CIao