SpringBoot+Quartz定时任务:Job类对象注⼊问题(定时任务报
错)
1、quartz的扫描的优先级⽐
@Autowired注⼊对象的优先级⾼;
2、可以使⽤springbean获取对象
eg:
ILeaseLeasorBlacklistService blacklistservice = Bean(ILeaseLeasorBlacklistService.class); ILeaseSupplierCompanyinforService companyinforservice = Bean(ILeaseSupplierCompanyinforService.class);
3、springUtils的代码如下:
package com.adminmon.utils.spring;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;
spring framework面试题import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.fig.BeanFactoryPostProcessor;
import org.springframework.fig.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
/**
* spring⼯具类⽅便在⾮spring管理环境中获取bean
*
* @author admin
*/
@Component
public final class SpringUtils implements BeanFactoryPostProcessor
{
/** Spring应⽤上下⽂环境 */
private static ConfigurableListableBeanFactory beanFactory;
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
{
SpringUtils.beanFactory = beanFactory;
}
/**
* 获取对象
*
* @param name
* @return Object ⼀个以所给名字注册的bean的实例
* @throws org.springframework.beans.BeansException
*
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException
{
return (T) Bean(name);
}
/
**
* 获取类型为requiredType的对象
*
* @param clz
* @return
* @throws org.springframework.beans.BeansException
*
*/
public static <T> T getBean(Class<T> clz) throws BeansException
{
T result = (T) Bean(clz);
return result;
}
/**
* 如果BeanFactory包含⼀个与所给名称匹配的bean定义,则返回true
*
* @param name
* @return boolean
*/
public static boolean containsBean(String name)
{
ainsBean(name);
}
/**
* 判断以给定名字注册的bean定义是⼀个singleton还是⼀个prototype。如果与给定名字相应的bean定义没有被到,将会抛出⼀个异常(NoSuchBeanDefinitionException) *
* @param name
* @return boolean
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException
{
return beanFactory.isSingleton(name);
}
/**
* @param name
* @return Class 注册对象的类型
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static Class<?> getType(String name) throws NoSuchBeanDefinitionException
{
Type(name);
}
/
**
* 如果给定的bean名字在bean定义中有别名,则返回这些别名
*
* @param name
* @return
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
*
*/
public static String[] getAliases(String name) throws NoSuchBeanDefinitionException
{
Aliases(name);
}
/**
* 获取aop代理对象
*
* @param invoker
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getAopProxy(T invoker)
{
return (T) AopContext.currentProxy();
}
}
4、获取对象代码
LeaseLeasorBlacklistMapper leaseLeasorBlacklistMapper = Bean(LeaseLeasorBlacklistMapper.class);
来来关注下,认识下
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论