Mybatis-Spring mapper Interface Cannot resolve

1,056 views
Skip to first unread message

Detali

unread,
May 26, 2011, 8:50:43 AM5/26/11
to mybatis-user
i am working on mybatis-spring - Integration in my project

i have noticed following error while test this class. need a help
urgently
.
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'fixedIncomeMapper' defined in class path
resource [lvfi-dao.xml]: Cannot resolve reference to
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named '**.FixedIncomeMapper' is defined

MY lvfi-data.xml has following code </n>

<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
</bean>
</n>
<bean id="fixedIncomeMapper"
class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface"
ref="com.*.mybatis.model.FixedIncomeMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</n>
</bean>
<bean id="fixedIncomeservice"
class="com.*.mybatis.dao.FixedIncomeServiceImpl">
<property name="fixedIncomeMapper" ref="fixedIncomeMapper" />
</bean>

TEST CLASS </n>
public class ProcessMapperTest extends TestCase{
public FixedIncomeService fixedIncomeservice;

public void setUp() throws Exception {
String[] configResource = { "lvfi-dao.xml" };
applicationContext = new
ClassPathXmlApplicationContext(configResource);
fixedIncomeservice=
applicationContext.getBean("fixedIncomeservice");
super.setUp();
}
</n>
public void testCcyDenomination() {
try {
List<CcyDenomination> lstCcyDenomination =
fixedIncomeservice.getTimeToMaturiy();
assertTrue("no record found for ccydenomination",
lstCcyDenomination.size() > 0);
} catch (Exception ex) {
System.out.println("Error: in testCcyDenomination::::"
+ ex);
}

}
</n>
Mapper Interface has following code
public interface FixedIncomeMapper {
public List<CcyDenomination> getTimeToMaturiy(double req);
}
</n>
Mapper XML has following code

<select id="getccydenom" resultMap="ccydenomrs" parameterType="double"
statementType="CALLABLE">
{call
dbo.get_fxd_incm_currency_grid(#{currency_req,javaType=double,jdbcType=NUMERIC})}
</select>
</n>
SERVICE CLASS has following code
public class FixedIncomeServiceImpl implements fixedIncomeservice{
private MapperFactoryBean fixedIncomeMapper;
@SuppressWarnings("unchecked")
public List<CcyDenomination> getTimeToMaturiy(double req){
try {
return
fixedIncomeMapper.getSqlSession().selectList("getccydenom",req);
} catch (Exception ex) {
logger.error("SQL error, while running -
getccydenom ", ex);
}
return null;
}
}

Eduardo

unread,
May 26, 2011, 1:50:20 PM5/26/11
to mybatis-user
Could you post your lvfi-dao.xml file? What are that asteriscs for?
> dbo.get_fxd_incm_currency_grid(#{currency_req,javaType=double,jdbcType=NUME RIC})}

Detali

unread,
May 26, 2011, 4:58:31 PM5/26/11
to mybatis-user
Those Asteriscs are package name

here is the lvfi-dao.xml

<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
</bean>

<bean id="fixedIncomeMapper"
class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface"
ref="com.jpm.mybatis.model.FixedIncomeMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</n>
</bean>
<bean id="fixedIncomeservice"
class="com.jpm.mybatis.dao.FixedIncomeServiceImpl">

Eduardo

unread,
May 26, 2011, 5:13:01 PM5/26/11
to mybatis-user
This line:
<property name="mapperInterface"
ref="com.jpm.mybatis.model.FixedIncomeMapper" />

should be:
<property name="mapperInterface"
value="com.jpm.mybatis.model.FixedIncomeMapper" />

Detali

unread,
May 26, 2011, 6:06:38 PM5/26/11
to mybatis-user

Thanks for quick reply , i have fixed that now it;s it throws error
like

Bean property 'fixedIncomeMapper' is not writable or has an invalid
setter method. Does the parameter type of the setter match the return
type of the getter?

<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="creditDataSource" />
<property name="configLocation" value="classpath:mybatis/Mybatis-
Config.xml" />
</bean>

<bean id="fixedIncomeMapper"
class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface"
value="com.jpm.pb.crdit.mybatis.model.FixedIncomeMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>


<bean id="fixedIncomeDAO"
class="com.jpm.pb.crdit.mybatis.dao.FixedIncomeDAOImpl">
<property name="fixedIncomeMapper" ref="fixedIncomeMapper" />
</bean>

<!-- <bean id="fixedMapper"
class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="com.jpm.pb.crdit.mybatis.model" />
</bean> -->

Eduardo

unread,
May 27, 2011, 11:18:47 AM5/27/11
to mybatis-user
I would say that your FixedIncomeDAOImpl misses a
setFixedIncomeMapper() method

Detali

unread,
May 27, 2011, 2:07:34 PM5/27/11
to mybatis-user
Appreciate your help
correct, that is i figure it out fixed the code ,but some how not gets
the Mapper reference in fixedIncomeDAOImpl.it;s just throw null
pointer. i am using mybatis-spring-1.0.1-SNAPSHOT.jar and
mybatis-3.0.5-SNAPSHOT.jar

(return fixedIncomeMapper.getTimeToMaturiy() never works )


public class FixedIncomeDAOImpl implements FixedIncomeDAO {
protected Logger logger =
LoggerFactory.getLogger(FixedIncomeDAOImpl.class);

@Autowired
private FixedIncomeMapper fixedIncomeMapper;

public FixedIncomeMapper getFixedIncomeMapper() {
return fixedIncomeMapper;
}

public void setFixedIncomeMapper(FixedIncomeMapper fixedIncomeMapper)
{
this.fixedIncomeMapper = fixedIncomeMapper;
}

@SuppressWarnings("unchecked")
public List<CcyDenomination> getTimeToMaturiy(double req){
try {
return fixedIncomeMapper.getTimeToMaturiy();
} catch (Exception ex) {
logger.error("SQL error, while running - getccydenom ", ex);
}
return null;
}
}

lvfi-data.xml

<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="creditDataSource" />
<property name="configLocation" value="classpath:mybatis/Mybatis-
Config.xml" />
</bean>

<bean id="fixedIncomeMapper"
class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface"
value="com.jpmorgan.pb.credit.mybatis.model.FixedIncomeMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

<bean id="fixedIncomeDAO"
class="com.jpmorgan.pb.credit.mybatis.dao.FixedIncomeDAOImpl">
<property name="fixedIncomeMapper" ref="fixedIncomeMapper" />
</bean>

FixedIncomeMapper.java

public interface FixedIncomeMapper {
public List<CcyDenomination> getTimeToMaturiy();
}

FixedIncomeMapper.xml
<mapper
namespace="com.jpmorgan.pb.credit.mybatis.model.FixedIncomeMapper">
<resultMap id="ccydenomrs" resultType="ccydenom">
<result property="ccydenomination" column="Currency_denominated"/>
</resultMap>

<select id="getTimeToMaturiy" resultMap="ccydenomrs"
statementType="CALLABLE">
{call dbo.get_fxd_incm_currency_grid()}
</select>
</mapper>

Eduardo

unread,
May 27, 2011, 4:07:05 PM5/27/11
to mybatis-user
Please post a stacktrace. That will help.

Richard Yee

unread,
May 27, 2011, 8:09:05 PM5/27/11
to mybati...@googlegroups.com
Is your autowiring set up properly? You should set the component scan element to the packages that have classes that need to be autowired. Use a debugger to see that fixedIncomeMapper is being autowired.

Richard

Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages