Spring <context: component-scan base-package = "groupid.aop" /> не может быть определен - PullRequest
0 голосов
/ 13 сентября 2018
        <?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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"


       xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd"

        >

<bean id="triangle1" class="groupid.aop.triangle">
<property name="name" value="triangle bean"></property>
</bean>
<bean id="circle1" class="groupid.aop.circle">
<property name="name" value="circle bean"></property>
</bean>
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <context:component-scan base-package="groupid.aop"/>

</beans>

я получаю сообщение об ошибке <context:component-scan base-package="groupid.aop"/> в этой строке.Я использую Maven, чтобы добавить зависимости для Spring и AOP.Я также добавил пространство имен для контекста.пожалуйста, дайте мне знать, если я что-то упустил.

1 Ответ

0 голосов
/ 13 сентября 2018

Вы ошиблись в объявлении пространств имен.Этот xml должен решить проблему:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.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">
    <bean id="triangle1" class="groupid.aop.triangle">
        <property name="name" value="triangle bean" />
    </bean>
    <bean id="circle1" class="groupid.aop.circle">
        <property name="name" value="circle bean" />
    </bean>
    <aop:aspectj-autoproxy proxy-target-class="true" />
    <context:component-scan
        base-package="groupid.aop" />
</beans>

В исходном XML у вас есть:

xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd          
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"

Как вы можете видеть, вы объявили дважды спринг-бобы (http://www.springframework.org/schema/beans/spring-beans.xsd и http://www.springframework.org/schema/beans/spring-beans-3.0.xsd)) и вы использовали контекстную версию 3.0 (http://www.springframework.org/schema/context/spring-context-3.0.xsd)

Я надеюсь, что это полезно

Angelo

...