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

Spring 应用程序上下文xml文件中的命名属性,spring,Spring,我想使用spring依赖项注入在我的web应用程序中注入一些对象 在EtudiantServiceImpl类中,我有: @Autowired private IEtudiantDao etudiantDao; 在教育课上,我有: @Autowired private EtudiantServiceImpl etudiantService; @Autowired public Etudiant etudiant; 在我的应用程序上下文xml文件中,我有以下内容: <bean name="

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

在EtudiantServiceImpl类中,我有:

@Autowired
private IEtudiantDao etudiantDao;
在教育课上,我有:

@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>

对于:and name=etudiant和首先,如果将其定义为自动连接,则不需要在XML文件中定义它。只需将eTudianAction注释为@Controller

@Controller
class EtudiantAction{

... Same as your code
}
EtudiantServiceImpl也是一样,注释为@Service

现在,您可以从上下文xml中删除整个属性标记,因为属性标记没有属性类。您可以指定ref或value。此外,您应该在类中使用接口EtudiantDao和EtudiantService,而不是具体的实现。
@Controller
class EtudiantAction{

... Same as your code
}