分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

mvc-dispatchar-servlet.xml文件报错

发布时间:2023-09-06 01:43责任编辑:赖小花关键词:xml
<?xmlversion="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" ??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ??????xmlns:context="http://www.springframework.org/schema/context" ??????xmlns:mvc="http://www.springframework.org/schema/mvc" ??????xmlns:jpa="http://www.springframework.org/schema/data/jpa" ??????xmlns:tx="http://www.springframework.org/schema/tx" ??????xsi:schemaLocation="http://www.springframework.org/schema/beans ?????http://www.springframework.org/schema/beans/spring-beans.xsd ?????http://www.springframework.org/schema/context ?????http://www.springframework.org/schema/context/spring-context.xsd ??????http://www.springframework.org/schema/mvc ?????http://www.springframework.org/schema/mvc/spring-mvc.xsd ?????http://www.springframework.org/schema/data/jpa ?????http://www.springframework.org/schema/data/jpa/spring-jpa.xsd ??????http://www.springframework.org/schema/tx ?????http://www.springframework.org/schema/tx/spring-tx.xsd"> ???<!--指明controller 所在包,并扫描其中的注解--> ???<context:component-scan base-package="com.euphe.controller"/> ???<!--静态资源(js、image等)的访问 --> ???<mvc:default-servlet-handler/> ???<!--开启注解 --> ???<mvc:annotation-driven/> ???<!--ViewResolver视图解析器--> ???<!--用于支持Servlet、JSP视图解析--> ???<beanid="jspViewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"> ???????<propertyname="viewClass" value="org.springframework.web.servlet.view.JstlView"/> ???????<propertyname="prefix" value="/WEB-INF/pages/"/> ???????<propertyname="suffix" value=".jsp"/> ???</bean> ???<!--表示JPARepository所在的包 --> ???<jpa:repositories base-package="com.euphe.repository"/> ???<!--链接到persistence.xml--> ???<beanid="entityManagerFactory"class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> ???????<propertyname="persistenceUnitName"value="defaultPersistenceUnit"/> ???</bean> ???<!--事务管理 --> ???<beanid="transactionManager"class="org.springframework.orm.jpa.JpaTransactionManager"> ???????<propertyname="entityManagerFactory"ref="entityManagerFactory"/> ???</bean> ???<!--开启事务管理注解 --> ???<tx:annotation-driven transaction-manager="transactionManager"/></beans>

error:找不到transaction-manager

问题:依赖错了

解决:之前的依赖是xmlns:tx="http://www.springframework.org/schema/cache"

后来观察别人的依赖,发现别人的依赖是代码中的/tx,这种就很无赖了,本身是自己添加进去的依赖,但添加依赖时可能会出错。

这种问题实际上经常会出现,尤其是eclipse特别贴心地帮你添加import时,但这也意味着他添加的import有可能不对。碰到明明类是对的,但具体的函数就是出不来的情况,也要考虑是不是import或依赖的类出了问题。

 

error:Failed to convert property value of type [java.lang.String] to required type [javax.persistence.EntityManagerFactory] for property ‘entityManagerFactory‘

问题:<tx:annotation-driven transaction-manager="transactionManager"/>,transactionManager类型不对

解决:这种问题,不要看表面,要学会从根源开始查找,以后的学习也是,这种明明是配置的问题,莫名出错时,要学会找根源。哪个是哪个的调用,调用的部分是否存在,调用的部分参数值是否有问题。因为你调用和依赖不对,你后面的配置肯定会出问题。

先是查看了transactionManager的依赖,在上面的事务管理部分,id是对的,既然是类型出了问题,那么再往后看,之前出错的部分写的是<propertyname="entityManagerFactory" value="entityManagerFactory"/>,如果这样写,后面部分的value就将"entityManagerFactory"变成了一个<value></value>中的tag,而不是一个entity

mvc-dispatchar-servlet.xml文件报错

原文地址:https://www.cnblogs.com/xym4869/p/8478106.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved