应用程序上下文 xml 文件中的命名属性
naming properties in application context xml file
我想使用 spring 依赖注入在我的 Web 应用程序中注入一些对象。
在 EtudiantServiceImpl
class 我有:
@Autowired
private IEtudiantDao etudiantDao;
在 EtudiantAction
class 我有 :
@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
for : <property name="etudiantService">
and name="etudiant"
and <property name="etudiantDao"
.
我该如何解决?
首先,如果您将其定义为"AutoWired",则无需在XML 文件中对其进行定义。只需将 EtudiantAction 注释为 @Controller
@Controller
class EtudiantAction{
... Same as your code
}
EtudiantServiceImpl 也一样,注解为@Service
现在您可以从上下文中删除整个内容xml
我想使用 spring 依赖注入在我的 Web 应用程序中注入一些对象。
在 EtudiantServiceImpl
class 我有:
@Autowired
private IEtudiantDao etudiantDao;
在 EtudiantAction
class 我有 :
@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
for : <property name="etudiantService">
and name="etudiant"
and <property name="etudiantDao"
.
我该如何解决?
首先,如果您将其定义为"AutoWired",则无需在XML 文件中对其进行定义。只需将 EtudiantAction 注释为 @Controller
@Controller
class EtudiantAction{
... Same as your code
}
EtudiantServiceImpl 也一样,注解为@Service
现在您可以从上下文中删除整个内容xml