【Java】spring事務控制配置報錯,application-persstence.xml文件中transaction-manager報紅

一、問題

配置spring持久層xml配置文件時,<tx:annotation-driven>標籤裏有個transaction-manager屬性一直紅色,很明顯有問題;
在這裏插入圖片描述

二、解決

1、只要在配置文件上加入:

xmlns:tx="
http://www.springframework.org/schema/cache"
xmlns:tx="http://www.springframework.org/schema/tx"

配置信息即可;
在這裏插入圖片描述

2、一波已平,一波又起,transaction-manager不報紅了,但是,beans又報錯了,信息如下:
在這裏插入圖片描述


Attribute "tx" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified for element "beans"

意思是綁定http://www.w3.org/2000/xmlns/的tx屬性已經被beans標籤特別定義了;但是我配置的文件頭明明定義的是:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

這個東西啊?

我如果把:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

去掉,則下面引用的xsi屬性就報錯了:
在這裏插入圖片描述
現在要的問題是,有兩個相同的屬性【xmlns:tx】:
在這裏插入圖片描述
這裏,因爲下面的屬性是我需要的,上面的那個屬性,我選擇刪除
即刪除下面這句:

xmlns:tx="http://www.springframework.org/schema/cache"

然後就不報錯了;
在這裏插入圖片描述

配置文件頭的源代碼如下:

<?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:jdbc="http://www.springframework.org/schema/jdbc"
       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">

完畢;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章