`
gushuizerotoone
  • 浏览: 173871 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

用@component的bean id, 在spring配置文件app.context.html中的引用

 
阅读更多
@Component
@Transactional
public class SchedulingTasks {
   
    final Logger logger = Logger.getLogger(SchedulingTasks.class);
   
    @Autowired
    PtlCodeDao ptlCodeDao;
   
}

在spring的配置文件app.context.xml中想引用这个SchedulingTasks,如果像上面的@Component没有后面跟名字的,则bean id 默认为头字母小写schedulingTasks.

@Autowired也可以正常用

===========================
@Component("up.portal.util.SchedulingTasks")
@Transactional
public class SchedulingTasks {
   
    final Logger logger = Logger.getLogger(SchedulingTasks.class);
   
    @Autowired
    PtlCodeDao ptlCodeDao;
   
}

在spring的配置文件app.context.xml中想引用这个SchedulingTasks,如果像上面的@Component后面跟名字"up.portal.util.SchedulingTasks"的,则bean id 为@Component的名字"up.portal.util.SchedulingTasks",如:

<!-- 清除过时的认证码 -->
    <bean id="rmCodeShedule"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="up.portal.util.SchedulingTasks" />
    <property name="targetMethod" value="timeRemoveCode" />
    <property name="concurrent" value="false" />
    </bean>
分享到:
评论

相关推荐

    spring_MVC源码

    弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件。本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mvc和rest小例子没有介绍到数据层的内容,...

    Spring注解 @Component、@Repository、@Service、@Controller区别

    通过配置`&lt;context:component-scan&gt;`标签,Spring可以在指定的包下自动扫描带有`@Component`、`@Repository`、`@Service`或`@Controller`注解的类,并将它们自动注册为bean。这种方式极大地提高了开发效率,特别是在...

    java中获得spring中的BEAN

    `getBean`方法接受一个String类型的参数,即配置文件中定义的Bean的ID,返回该Bean的实例。 #### 2. 使用注解方式 除了传统的XML配置方式外,Spring还支持基于注解的配置方式。这种方式更加简洁,不需要显式地编写...

    spring4.0 Configuration的使用.docx

    - **实现方式**:除了使用 **@Configuration** 来启动 Spring 容器之外,还可以在配置类中定义带有 **@Bean** 注解的方法,用于创建并注册具体的 Bean 实例。 - **示例代码**: ```java package ...

    Eclipse spring基本配置步骤

    如果你想让Spring自动发现和管理带有`@Component`、`@Service`、`@Repository`或`@Controller`注解的类,可以在配置文件中启用组件扫描。例如: ```xml &lt;context:component-scan base-package="com.example"/&gt; `...

    Spring项目的xsd文件大全

    在Spring框架中,XSD文件为Spring配置文件提供了语义化的元素和属性,使得开发者能够用XML来声明和配置bean、依赖关系、AOP代理、事务管理等。 1. Springmvc的XSD文件: 在Spring MVC中,`spring-mvc.xsd`通常被...

    SpringMVC两种配置的Demo

    在Java配置中,你可以使用`WebApplicationInitializer`接口或`SpringBootServletInitializer`(对于Spring Boot项目)来替代`web.xml`。 ```java import org.springframework.web.WebApplicationInitializer; ...

    Maven 搭建Spring + SpringMVC.rar

    在这个配置文件中,我们可以声明Bean,如数据源、事务管理器以及SpringMVC的DispatcherServlet配置。 ```xml &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...

    http://www.robinhowlett.com/blog/2013/02/13/spring-app-migration-from-xml-to-jav

    3. **类型安全的依赖注入**:在Java配置中,可以直接通过方法参数来注入其他bean,Spring容器会在运行时确保注入正确类型的bean,这比XML配置的字符串id引用更安全。 4. **自动扫描和组件注解**:`@Component`、`@...

    spring2 集成视图

    至此,我们已经介绍了如何在Spring2中集成视图,包括配置`DispatcherServlet`、视图解析器、创建Controller以及使用JSP、FreeMarker和Thymeleaf等不同视图技术。理解并熟练掌握这些知识点,能够帮助开发者构建高效、...

    Spring实战之Qualifier注解用法示例

    在Spring配置文件中,我们需要使用&lt;context:component-scan&gt;元素来启用自动装配。下面是一个示例配置文件: ```xml &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...

    分模块开发配置文件

    在分模块开发中,每个模块可能有独立的Controller层,因此我们需要在Spring的配置文件(如`app-context.xml`)中对这些Controller进行注册。使用`&lt;bean&gt;`标签定义Controller Bean,并通过`@Controller`注解标记...

    Eclipse中spring mvc配置实例

    在本文中,我们将深入探讨如何在Eclipse集成开发环境中配置Spring MVC框架,以实现一个简单的登录页面示例。Spring MVC是Spring框架的一部分,它提供了一种模型-视图-控制器(MVC)架构来构建Web应用程序。让我们一...

    Spring3.0 MVC配置教程

    在这个教程中,我们将深入探讨Spring 3.0版本的MVC配置。 一、环境准备 在开始配置Spring MVC之前,确保你已经安装了以下工具: 1. Java Development Kit (JDK):Spring 3.0支持JDK 1.5及以上版本。 2. Apache ...

    使用maven简单搭建Spring mvc + redis缓存

    在Spring的配置文件中,创建一个`JedisConnectionFactory`并配置连接参数: ```xml &lt;bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"&gt; ...

    手写Spring框架之: HelloSpring

    除了XML配置,Spring还支持基于注解的配置,如使用`@Component`、`@Service`、`@Repository`和`@Controller`注解来标记Bean,以及使用`@Autowired`自动装配依赖。这种配置方式更简洁,但原理与XML配置相同。 通过这...

    简单spring MVC 配置

    在本篇文章中,我们将详细探讨如何配置一个简单的Spring MVC应用。 #### 二、搭建Java项目与基础配置 **1. 创建项目** 首先,我们需要创建一个新的Java Web项目。这可以通过IDE(如Eclipse或IntelliJ IDEA)完成...

    spring5.0_mvc_maven项目_HelloWorld实例

    在这个"HelloWorld"实例中,我们将深入探讨如何使用Spring 5.0 MVC和Maven构建一个基本的应用程序。 首先,让我们了解Spring MVC的核心组件: 1. **DispatcherServlet**:它是Spring MVC的前端控制器,负责接收...

    搭建Spring项目

    在项目中右键选择"Build Path" -&gt; "Configure Build Path" -&gt; "Libraries",然后点击"Add External JARs",将Spring框架的库文件(如spring-context、spring-web等)添加到项目的类路径中。这些库通常可以从Spring...

Global site tag (gtag.js) - Google Analytics