做了一个小程序,用了spring+mybatis然后在eclipse里面测试都是正常的,可以运行。打包成jar后就出错了。出错提示为:
[WARN ] 2011-11-07 14:38:29 :No MyBatis mapper was found in 'com.dddd.mybatis.pernsistence' package. Please check your configuration.
....................
xception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitio
nException: No bean named 'youZhengServiceImpl' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBeanDefinition(DefaultListableBeanFactory.java:527)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMerg
edLocalBeanDefinition(AbstractBeanFactory.java:1087)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
an(AbstractBeanFactory.java:278)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:194)
        at org.springframework.context.support.AbstractApplicationContext.getBea
n(AbstractApplicationContext.java:1093)
        at 'com.dddd.YouZheng.doStart(YouZheng.java:41)求解。附带的包肯定没错,我在另外一台干净的电脑上重新安装了jre和eclipse测试的依然一样,
在eclipse里面可以运行,打包后就行。

解决方案 »

  1.   

    配置文件没有弄出来吧?
    报错 No bean named 'youZhengServiceImpl' is defined
      

  2.   

    这是主要配置文件,我把数据源及事务的删除了。其它没变

    <!-- enable autowire -->
    <context:annotation-config />
    <!-- enable component scanning (beware that this does not enable mapper scanning!) -->
    <context:component-scan base-package="mingshu.mybatis.service" />    <!-- enable transaction demarcation with annotations -->
        <tx:annotation-driven />
    <!-- define the SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="typeAliasesPackage" value="mingshu.mybatis.domain" />
    </bean>
    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="mingshu.mybatis.persistence" />
    </bean>
      

  3.   

    youZhengServiceImpl 你配置在哪里的?
      

  4.   

       <!-- enable autowire -->
        <context:annotation-config />
        <!-- enable component scanning (beware that this does not enable mapper scanning!) -->
        <context:component-scan base-package="mingshu.mybatis.service" />我全部是注释的。这个会自动去找。