【发布时间】:2013-01-19 11:57:35
【问题描述】:
我正在学习 Spring MVC,我找到了这个简单的 Hello World 教程:http://www.tutorialspoint.com/spring/spring_hello_world_example.htm
在本教程中,作者创建了一个名为 Beans.xml 的 Bean 配置文件,如下所示:
<?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>
使用 tis 文件,Spring 框架可以创建所有定义的 bean,并为它们分配一个唯一的 ID,如标签中定义的那样。我可以使用标签来传递创建对象时使用的不同变量的值。
这是众所周知的豆厂吗?
我的疑问与以下事情有关:在我之前的示例中,我没有使用 Bean 配置文件来定义我的 bean,但是我使用注解来定义什么是 Spring bean 以及这个 bean 是如何工作的(例如我使用 @Controller 注释说 Spring 一个类充当控制器 Bean)
使用bean配置文件和使用注解意思一样吗?
我可以同时使用吗?
例如,如果我必须配置 JDBC,我可以在 beans.xml 文件中配置它,同时我可以为我的 Controller 类使用注释吗?
Tnx
【问题讨论】:
标签: java spring spring-mvc