#java #xml #spring #spring-mvc #aop
#java #xml #spring #spring-mvc #aop
Вопрос:
У меня есть проект Spring MvC, использующий JPA и Oracle в качестве базы данных, у меня есть это объявление компонента в моем servlet.xml файл, но когда я запускаю тест
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
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/tx
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="bbtra"
class="com.bonanza.commons.services.TranslationDB"
autowire-candidate="true">
<property name="dataSource" ref="dataSource" />
<aop:scoped-proxy/>
</bean>
Я получил эту ошибку:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:scoped-proxy'.
Ответ №1:
Обычно на *.xsd
файлы ссылаются https://
вместо http://
, но это не проблема, я просто упоминаю об этом. Минимальное изменение в вашем XML-файле, устраняющее проблему, движется вверх spring-tx.xsd
, чтобы быть сразу позади tx
. Тогда также изменится подсветка в вашем редакторе XML, т. Е. В IntelliJ IDEA вы увидите, что материал AOP меняется с серого на зеленый. Я имею в виду:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
"
>
<bean id="bbtra"
class="com.bonanza.commons.services.TranslationDB"
autowire-candidate="true">
<property name="dataSource" ref="dataSource" />
<aop:scoped-proxy/>
</bean>
</beans>
Теперь все расположения схемы schema/foo
и schema/foo/spring-foo.xsd
образуют пары.
Ответ №2:
Скорее всего, расположение схемы пространства имен aop не указано:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- bean definitions here -->
</beans>
Комментарии:
1. Все необходимые элементы были указаны в конфигурации OP, как вы можете легко увидеть, если проверите, что он опубликовал. Неправильным был порядок расположения схемы.
2. @kriegaex К сожалению, объявления пространства имен были добавлены после того, как был дан этот ответ. Первоначально это было разумное предположение.
3. О, мне так жаль. Пожалуйста, примите мои извинения, я не сравнивал временную метку редактирования с вашим ответом.