【问题标题】:create beans with annotation spring创建带有注释spring的bean
【发布时间】:2013-05-08 11:18:42
【问题描述】:

在 struts2 中,我几乎没有使用任何 xml 配置,而是为 MVC 使用了很多注释。我使用 struts2 以这种方式构建了一个小型应用程序。现在我想使用 spring 3.2 开发相同的项目。现在我想使用注释来创建 bean 和请求映射(我使用过这个)。我想要一个使用 bean 注释的清晰示例,是否可以使用注释设置属性。我很困惑,因为文档太大,而且注释很多。通过简单的示例提供一个简单的注释列表及其用法会很有帮助。

【问题讨论】:

    标签: spring spring-mvc annotations spring-annotations


    【解决方案1】:

    我正在 Spring 3.1 上做示例项目。 我使用了一些注释来创建 bean。以下是我使用的注释。 @Component - 用于创建 Spring 提供的 bean 的注解 @资源,@Bean JSR 注解:@Controller、@Repository、@Service

    如果您使用上述注释来注释您的类,Spring Container 将为您创建 bean。

    您的属性将在 @Autowired 注释的帮助下设置。

    【讨论】:

    • 感谢您的回答。我想知道,spring 是否会自动为 @Bean 注释的类创建单例,或者我们必须在哪里注册这些类?
    猜你喜欢
    • 2015-12-14
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 2012-07-08
    • 2012-09-03
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多