spring mybatis 整合异常

NewshiJ 2017-01-16 11:02:17
一月 16, 2017 10:57:49 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not exist
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:732)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not exist
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:596)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:216)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1491)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1231)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
... 20 more
Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not exist
at org.springframework.core.io.support.ResourceArrayPropertyEditor.setAsText(ResourceArrayPropertyEditor.java:116)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:468)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:441)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:199)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
... 26 more

一月 16, 2017 10:57:49 上午 org.apache.catalina.core.StandardContext startInternal
严重: One or more listeners failed to start. Full details will be found in the appropriate container log file
一月 16, 2017 10:57:49 上午 org.apache.catalina.core.StandardContext startInternal
严重: Context [] startup failed due to previous errors
一月 16, 2017 10:57:49 上午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
一月 16, 2017 10:57:49 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8080"]
一月 16, 2017 10:57:49 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-8009"]
一月 16, 2017 10:57:49 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 5746 ms
各位大神帮忙看看
...全文
539 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
狼王_ 2017-01-19
  • 打赏
  • 举报
回复
引用 13 楼 cmmchenmm 的回复:
多谢各位的好心帮助,现在我已经解决完了,谢谢大家
怎么解决的啊?
NewshiJ 2017-01-18
  • 打赏
  • 举报
回复
多谢各位的好心帮助,现在我已经解决完了,谢谢大家
zwbonline1112 2017-01-16
  • 打赏
  • 举报
回复
引用 7 楼 hz890 的回复:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="mapperLocations" value="classpath:fjun/mapper/*.xml" /> </bean> 楼主把fjun写成了fjnu
我日。。。
hz890 2017-01-16
  • 打赏
  • 举报
回复
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="mapperLocations" value="classpath:fjun/mapper/*.xml" /> </bean> 楼主把fjun写成了fjnu
NewshiJ 2017-01-16
  • 打赏
  • 举报
回复
zwbonline1112 2017-01-16
  • 打赏
  • 举报
回复
引用 4 楼 dsiori 的回复:
<property name="mapperLocations" value="classpath:fjnu/mapper/*.xml" /> ?? 这里我没弄懂,classpath 有“/” 斜杠这种写法?
有,楼主把项目的包结构截个图看看
dsiori 2017-01-16
  • 打赏
  • 举报
回复
<property name="mapperLocations" value="classpath:fjnu/mapper/*.xml" /> ?? 这里我没弄懂,classpath 有“/” 斜杠这种写法?
dsiori 2017-01-16
  • 打赏
  • 举报
回复
Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not exist 异常这里说了,没有找到你的配置文件。而且参数错误
NewshiJ 2017-01-16
  • 打赏
  • 举报
回复
<?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:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/tx  
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">  
	
	<!-- 1. 数据源 : DriverManagerDataSource -->  
    <bean id="dataSource"  
        class="org.apache.commons.dbcp.BasicDataSource">  
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
        <property name="url" value="jdbc:mysql://localhost:3306/graduation" />  
        <property name="username" value="root" />  
        <property name="password" value="123456" />  
    </bean> 
    
    <!--  
        2. mybatis的SqlSession的工厂: SqlSessionFactoryBean dataSource:引用数据源  
  
        MyBatis定义数据源,同意加载配置  
    -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource"></property>  
        <property name="mapperLocations" value="classpath:fjnu/mapper/*.xml" />   
    </bean>   
      
    <!--  
        3. mybatis自动扫描加载Sql映射文件/接口 : MapperScannerConfigurer sqlSessionFactory  
  
        basePackage:指定sql映射文件/接口所在的包(自动扫描)  
    -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="fjun.dao"></property>  
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
    </bean>  
    
    <!-- 
        4. 事务管理 : DataSourceTransactionManager dataSource:引用上面定义的数据源 
    -->  
    <bean id="transactionManager"  
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"></property>  
    </bean>  
  
    <!-- 5. 使用声明式事务  
         transaction-manager:引用上面定义的事务管理器  
     -->  
    <tx:annotation-driven transaction-manager="transactionManager" />   
    <context:component-scan base-package="fjun" />      
</beans>
zwbonline1112 2017-01-16
  • 打赏
  • 举报
回复
加载不到.xml文件
hz890 2017-01-16
  • 打赏
  • 举报
回复
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\JAVA\mars\java 项目\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Graduation\WEB-INF\classes\fjun\mapper\Employee.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'fjun.entity.Employee'. Cause: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee 这个问题,或许要看一下楼主的fjun\mapper\Employee.xml文件。
NewshiJ 2017-01-16
  • 打赏
  • 举报
回复
NewshiJ 2017-01-16
  • 打赏
  • 举报
回复
<?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:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/tx  
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">  
	
	<!-- 1. 数据源 : DriverManagerDataSource -->  
    <bean id="dataSource"  
        class="org.apache.commons.dbcp.BasicDataSource">  
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
        <property name="url" value="jdbc:mysql://localhost:3306/graduation" />  
        <property name="username" value="root" />  
        <property name="password" value="123456" />  
    </bean> 
    
    <!--  
        2. mybatis的SqlSession的工厂: SqlSessionFactoryBean dataSource:引用数据源  
  
        MyBatis定义数据源,同意加载配置  
    -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource"></property>  
        <property name="mapperLocations" value="classpath:fjun/mapper/*.xml" />   
    </bean>   
      
    <!--  
        3. mybatis自动扫描加载Sql映射文件/接口 : MapperScannerConfigurer sqlSessionFactory  
  
        basePackage:指定sql映射文件/接口所在的包(自动扫描)  
    -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="fjun.dao"></property>  
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
    </bean>  
    
    <!-- 
        4. 事务管理 : DataSourceTransactionManager dataSource:引用上面定义的数据源 
    -->  
    <bean id="transactionManager"  
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource"></property>  
    </bean>  
  
    <!-- 5. 使用声明式事务  
         transaction-manager:引用上面定义的事务管理器  
     -->  
    <tx:annotation-driven transaction-manager="transactionManager" />   
    <context:component-scan base-package="fjun" />      
</beans>
NewshiJ 2017-01-16
  • 打赏
  • 举报
回复
大神改完之后又有新的问题了 一月 16, 2017 3:18:47 下午 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\JAVA\mars\java 项目\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Graduation\WEB-INF\classes\fjun\mapper\Employee.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'fjun.entity.Employee'. Cause: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:732) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\JAVA\mars\java 项目\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Graduation\WEB-INF\classes\fjun\mapper\Employee.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'fjun.entity.Employee'. Cause: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:466) at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:340) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ... 21 more Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'fjun.entity.Employee'. Cause: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120) at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92) at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:464) ... 24 more Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'fjun.entity.Employee'. Cause: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:118) at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:74) at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135) at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128) at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118) ... 26 more Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'fjun.entity.Employee'. Cause: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:120) at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149) at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116) ... 30 more Caused by: java.lang.ClassNotFoundException: Cannot find class: fjun.entity.Employee at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:200) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89) at org.apache.ibatis.io.Resources.classForName(Resources.java:261) at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:116) ... 32 more 一月 16, 2017 3:18:47 下午 org.apache.catalina.core.StandardContext startInternal 严重: One or more listeners failed to start. Full details will be found in the appropriate container log file 一月 16, 2017 3:18:47 下午 org.apache.catalina.core.StandardContext startInternal 严重: Context [] startup failed due to previous errors 一月 16, 2017 3:18:47 下午 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 一月 16, 2017 3:18:47 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 一月 16, 2017 3:18:47 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 一月 16, 2017 3:18:47 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 5644 ms

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧