当前位置: 首页 > 知识库问答 >
问题:

Spring,XMLCOnfiguration:在xml文件中没有说明注释,它是如何工作的?

微生高谊
2023-03-14

我正在尝试使用xml文件中的注释配置编写一个Spring程序,它在没有启动此配置的情况下也可以工作。我在一个文件中编写了method(),并用Beans.xml文件声明了CLassPathXmlApplication Context,我编写了一个学生bean并为setter方法应用了@必需注释,请在下面找到Bean配置xml文件:

<?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:context = "http://www.springframework.org/schema/context"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
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">

<context:annotation-config/>

<!-- Definition for student bean -->
<bean id = "student" class = "com.tutorialspoint.Student">
  <property name = "name" value = "Zara" />
  <property name = "age"  value = "11"/>
</bean>

</beans>

当我在xml文件中运行这个程序时,无论是否有以下注释指示,代码都可以正常工作,请告诉我其根本原因。

<context:annotation-config/>

共有1个答案

公冶峰
2023-03-14

Required注释适用于bean属性setter方法,它指示必须在配置时在XML配置文件中填充受影响的bean属性。

一旦<代码>

在您的xml中,您已经定义了您的属性,因此@必需的将运行良好

 类似资料:
  • 所以我知道通过这个注释: 此方法处理对URL/Orders表示的资源发出的GET HTTP请求。 此方法调用返回列表的DAO对象。 确保结果将由HTTP消息转换器(而不是MVC视图)写入HTTP响应。 也可以阅读Spring官方文档:http://docs.Spring.io/Spring/docs/current/javadoc-api/org/springframework/web/bind/

  • 我使用ASP.NETCore创建了一个Web API,并使用swagger创建留档。我使用APIendpoint上的XML注释在留档中提供附加信息。swagger配置是: 我的一个APIendpoint及其XML注释是: 是一个单独的类,它是APIendpoint所需参数的包装器。 此 API 终结点的 swagger 文档将 VisitorSearchCriteria 的所有属性显示为参数,但它

  • 问题内容: 我正在学习RoR /数据库,这个话题特别让我感到困惑。在《 用Rails开发敏捷4 》一书中,他们给出了一个示例,该示例查找名为Dave的条目的所有订单的列表: 这本书接着说,您永远都不想做这样的事情: 相反,您应该这样做: 我了解什么是SQL注入概念,但是有一些细节使我感到困惑。对于初学者来说,SQL注入作为一种语法到底是如何工作的。 我得到的危险是,如果像第一个示例那样插入外部表单

  • 当我使用Spring Framework时,我使用Java注释将类标记为控制器,使用@Request estMap()等方法。我不知道哪个类阅读这些注释以及使用了什么技术。我在想Java反射。对吗?