在应用程序上下文xml文件中命名属性

时间:2015-01-02 03:20:19

标签: spring

我想使用spring依赖注入在我的Web应用程序中注入一些对象。

EtudiantServiceImpl课程中,我有:

@Autowired
private IEtudiantDao etudiantDao;

EtudiantAction课程中,我有:

@Autowired
private EtudiantServiceImpl etudiantService;
@Autowired
public Etudiant etudiant;

在我的应用程序上下文xml文件中,我有这个:

<bean name="etudiantAction" class="tp.ihm.gestionEtudiants.web.EtudiantAction" scope="prototype">
         <property name="etudiantService">
            <ref bean="etudiantService"/>
         </property>
         <property name="etudiant" class="tp.ihm.gestionEtudiants.domain.Etudiant">
         </property>
    </bean>

    <bean id="etudiantService" class="tp.ihm.gestionEtudiants.service.EtudiantServiceImpl">
        <property name="etudiantDao" class="tp.ihm.gestionEtudiant.dao.EtudiantDaoImpl">
        </property>
    </bean>

但我在xml文件中收到错误:

Attribute : name
The name of the property, following JavaBean naming conventions.

Data Type : string

代表:<property name="etudiantService">name="etudiant"以及<property name="etudiantDao"

我该如何解决?

1 个答案:

答案 0 :(得分:0)

首先,如果您将其定义为&#34; AutoWired&#34;,则不需要在XML文件中定义它。只需将EtudiantAction注释为@Controller

即可
@Controller
class EtudiantAction{

... Same as your code
}

EtudiantServiceImpl也是一样,注释为@Service

现在您可以从上下文xml中删除整个