我正在学习 Spring MVC.今天,想了解如何实现一个 JDBC DAO,我发现了这个Hello World".在 Spring(Spring,而不是 Spring MVC)中,我开始看到它(因为我认为要实现 DAO,我必须创建一个单独的 Spring Project 来执行对数据的访问......)
I am studying Spring MVC. Today,trying to understand how implement a JDBC DAO,I have found this "Hello World" in Spring (Spring,not Spring MVC) and I begin to see it (because I think that to realize a DAO I have to create a separate Spring Project that execute the access to the data...)
http://www.tutorialspoint.com/spring/spring_hello_world_example.htm
好的,这是一个独立的应用程序,这不是一个 Web 应用程序,因此它没有我的 Web 中的 Web 应用程序结构(WEB-INF 文件夹、web.xml 文件和调度程序 servlet 配置文件)应用程序)
在本例中,我有一个 Beans.xml 配置文件,用于为不同的 bean 分配唯一 ID,并控制具有不同值的对象的创建,而不会影响任何 Spring 源文件...
例如在这个例子中,我使用 Beans.xml 文件来传递Hello World".消息"的消息值变量,所以我可以打印这个值而不影响 HelloWorld.java 和 MainApp.java 文件
For example in this example I use the Beans.xml file to pass the "Hello World" message value for "message" variable and so I can print this value without impacting HelloWorld.java and MainApp.java files
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="helloWorld" class="com.tutorialspoint.HelloWorld"> <property name="message" value="Hello World!"/> </bean> </beans>
所以我有一些问题要问你:
这个文件是配置我的Bean Factory的文件吗?我认为,除了将文本值作为变量的值传递之外,我还可以注入一个 bean 作为另一个 bean 的依赖项.
Is this file the file that configure my Bean Factory? I think that,as well as I pass a text value as the value of a variable I could also inject a bean as a dependency of another bean.
对吗?
在这个例子中,我可以不使用Beans.xml文件来代替注解系统吗?