1.å¦ä½å¨jbpmçhandlerä¸è½å¤ä½¿ç¨ç±spring管ççbean对象
2.driver does not support get/ set network timeout for connections什么意思?
å¦ä½å¨jbpmçhandlerä¸è½å¤ä½¿ç¨ç±spring管ççbean对象
å¦ä½å¨jbpmçhandlerä¸è½å¤ä½¿ç¨ç±spring管ççbean对象å¢ï¼
é¦å å æ¥ç解springä¸å¯¹JavaBeanç管çæºå¶ãSpring容å¨æ管ççbean对象é½æ¯ç±beanFacotryå·¥åæ¥å®ä¾åï¼æ以è¦ä½¿ç¨pring容å¨ä¸beanå®ä¾å¯¹è±¡ï¼å¿ 须该类ä¹æ¯ç±spring容å¨æ管çï¼å¦åæ æ³ä»beanå·¥åä¸å¾å°beanå®ä¾å¯¹è±¡ã
ç解äºä¸é¢çç®åéè¿°ä¹åï¼ä¸é¢ææ¥ççå¨jbpmä¸æ¯å¦ä½è®¿é®spring容å¨ä¸çbean对象ç
å¨ä¸ä¸ªå°jbpméæå°sshæ¶æä¸é¡¹ç®ä¸ï¼è¦æ³å¨ä¸ä¸ªç±jbpmæ管ççjavaç±»ä¸è®¿é®spring容å¨ä¸javabeanï¼å¦ä½è®¿é®å¢ï¼
Struts ææ°çæ¬ä¸æ¯ç±
æ们å æå¼struts2ä¸é¨æ¥çspringï¼é£ä¹æ们就ä»springæ åé ç½®æ件æ¥è¯´èµ·ï¼å¦æä½ è¦åæ个ç±spring管çç对象ä¸æ³¨å ¥ä¸ä¸ªå¯¹è±¡ï¼æ们该å¦ä½å»åå¢?码原举ä¾è¯´æï¼å¦æç±ä¸¤ä¸ªå¯¹è±¡AãBï¼ç°å¨éè¦å¨B对象ä¸ä½¿ç¨A对象ï¼é£ä¹æ们éè¿ä»ä¹æ¹å¼å°Aæ³¨å ¥å°Bä¸å»å¢ï¼é¦å AãB两个对象é½å¿ é¡»æ¯ç±spring容å¨æ¥ç®¡çï¼é£ä¹æ们就éè¦å¨é ç½®æ件å®ä¹property å±æ§æ¥æ³¨å ¥ï¼ç°å¨AãBé½æspring容å¨æ¥ç®¡ççï¼é£ä¹æå¦ä½å¾å°å ¶ä¸A对象å¢ï¼å 为AB对象é½æ¯ç±spring容å¨æ¥å建çï¼æ以è¦æ³å¾å°A对象ï¼å°±é¦å å¾å°BeanFactory--->GetA(),ç¶åæè½æ¿å°Aï¼è¿æ¶AæåB对象çå¼ç¨ææå¼ï¼æè½æAæ³¨å ¥å°Bä¸ã
ç解äºä¸é¢çspring管çæºå¶åï¼ä¸é¢æ们就æ¥è®¨è®ºå¦ä½å¨jbpmçhandlerä¸è®¿é®ç±spring管ççbean对象å¢ï¼
1ã 第ä¸ç§ä¸æ¨èçæ¹å¼ï¼
å¨springé ç½®æ件ä¸é ç½®å¦ä¸ï¼
Java代ç
<bean id="roleAssignmentHandler" class="com.oa.service.handler.RoleAssignmentHandler">
<property name="userService" ref="userService" />
</bean>
å®ä¹ä¸ä¸ªç±»åé(éæçstatic,è¿ä¸ªç±»çææå®ä¾å ±äº«çåé)ï¼å¯å¨æå¡å¨æ¶ï¼åå§åspringæ¶å°±å建äºBeanFactoryï¼å¨å建BeanFacotryæ¶ï¼å°±å®ä¾åäºææ对象ãä¹å°±è¯´ä¹å°±å建äºä¸ä¸ªroleAssignmentHandler 对象ï¼æ¾å°äºå®èªå·±å®¹å¨çé£åå åä¸ï¼è¿ä¸ªå¯¹è±¡æ¥æä¸ä¸ªæåuserServiceçå¼ç¨ï¼å 为æå¨è¿éå®ä¹çæ¯ç±»åéãçä¸æ¬¡å¨å建è¿ä¸ªå¯¹è±¡æ¶ï¼å¨è¿ä¸ªç±»åéä¸åæ ·æ¯æå¼ãä½æ¯è¿ç§æ¹æ³å¹¶ä¸æ¨èï¼è¿ç§æ¹å¼æç¹æµªè´¹å å空é´ï¼springå·²ç»ç»æ们å建äºå¯¹è±¡ï¼ä½æ¯æ们并没æå»ä½¿ç¨å®ã
Java代ç
public class RoleAssignmentHandler implements AssignmentHandler {
private static UserService userService;
public void setUserService(UserService _userService) {
userService = _userService;
}
â¦â¦
2ã 第äºç§ä¸æ¨èçæ¹å¼ï¼
Pringå®æ¯ä¸ªå®¹å¨ï¼åæ ·å®æ¯ä¸ªBeanå·¥åï¼å¦ææ们springçæ个beanå·¥åçè¯ï¼é£ä¹æå°±å¯ä»¥ä»BeanFactoryä¸å¾å°æ们çbean对象ï¼é£ä¹å¦ä½å»å¾å°BeanFactory对象å¢ï¼
æä¸è½åå¾å¸¸åæµè¯é£æ ·éè¿new ClassPathXmlApplicationContext("");æ¥å建å®ï¼æ们éè¦ä»å½åç¯å¢ä¸å»æ¿ï¼é£ä¹ä»ä»ä¹å°æ¹å»æ¿å¢ï¼é£ä¹å°±å¾æç½å®æ¯å¦ä½å建çï¼ç±è°æ¥å建并管ççï¼å¨æå¡å¨å¯å¨æ¶ï¼å®å°±ä¼åå§åweb.xmlä¸çlinsteneré 置信æ¯ï¼å建ä¸ä¸ªBeanâFactroy对象ï¼å¹¶æè¿ä¸ªå¯¹è±¡æ¾å°äºServletContextä¸ï¼æ们å¯ä»¥å©ç¨springä¸çä¸ä¸ªå·¥å ·ç±»æ¥å¾å°ServletContextä¸çBeanFactory对象ï¼ä½æ¯å¹¶æ¨èï¼å 为ServletActionContextæ¯Strutsä¸çï¼å¨ä¸å¡é»è¾ä¸è¿åä¾èµäºå±ç°å±çå 容ï¼JBPMæ¯ä¸ä¾èµäºå±ç°å±å 容çï¼ä¹ä¸æ¨èäºä¾èµå ³ç³»çåå¨ã
Java代ç
BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
UserService userService = factory.getBean("userService");
3ã 第ä¸ç§å¹¶ä¸æ¨èçæ¹å¼
å¨é¡¹ç®å¼åä¸éç¨SSHä¸JBPMéææ¶ï¼ç¨å°äºä¸ä¸ªç¬¬ä¸æ¹çéæå ï¼æ们å¯ä»¥ä»è¿éå¾å°è§£å³æ¹æ¡ï¼ï¼éç¨jbpm3.1æä»¥å ¶ç¬¬ä¸æ¹éæå 为spring-modules-jbpm.jarï¼å¨å ¶ææ¡£ï¼jbpm.htmlï¼ä¸å¯ä»¥äºè§£å°ï¼éç¨å¦ä¸é ç½®ï¼
æµç¨å®ä¹æ件é ç½®
Java代ç
<assignment class="com.oa.service.handler.RoleAssignmentHandler">
<targetBean>roleAssignmentHandler</targetBean>
</assignment>
å¨springé ç½®æ件ä¸å¯ä»¥è¿æ ·å®ä¹å¦ä¸
Java代ç
<bean id="roleAssignmentHandler" class="com.oa.service.handler.RoleAssignmentHandler">
<property name="userService" ref="userService" />
<property name="roleName" value="ç³»ç»ç®¡çå"/>
</bean>
ä½è¿æ¯ç§æ¹æ³å¹¶ä¸æ¯å¾çµæ´»ï¼æäºä¸è¥¿å·²ç»åæ»å¨é ç½®æ件ä¸äºï¼æ以æ们并æ¨èæ¤æ¹å¼ï¼é£ä¹æ们å¦ä½æ¥å¾å°ä¸ä¸ªå¥½ç解å³æ¹æ¡å¢ï¼
4ã 第åç§æ¹å¼ï¼
åè¿å¤´æ¥ï¼æ们æ¥ç继ç»æèä»BeanFactoryä¸å»è·å¾ï¼æµç¨å®ä¹æ件并ä¸å»ä¿®æ¹å®ï¼è¿æ ·å°±ä¸ä¼ç ´åå®ççµæ´»æ§ï¼é£ä¹æ¥ä¸æ¥è¦åæçé®é¢å°±æ¯å¦ä½æ¥è·å¾BeanFactoryå¢ï¼é£å°±å¾æ·±å ¥äºè§£ä¸ä¸springï¼ç°å¨æ¥çä¸ä¸ªé®é¢ï¼å¨ä¸ä¸ªåä¾ä¸å¦ä½è·å¾ä¸ä¸ªéåä¾ç对象å¢ï¼ä¹å°±æ¯å°Bæ³¨å ¥å°Aä¸ Aæ¯åä¾ï¼ä½æ¯Bä¸æ¯åä¾ï¼ç´æ¥éç¨Resourceæå¨é ç½®æ件å©ç¨propertyæ³¨å ¥çè¯ï¼æ¯æ æ³å®ç°çï¼åªè½å°Båæä¸ä¸ªåä¾å¯¹è±¡æ¥ä½¿ç¨ãé£ä¹æ们å¨åä¾å¯¹è±¡ä¸å¦ä½å¨æè·åä¾èµå¯¹è±¡å¢ï¼æä¸ç§æ¹å¼å°±ä»å®çBeanFactoryä¸å»è·å¾å ¶å¯¹è±¡ï¼å¦ä½å¨ç±spring管çç对象ä¸æ¿å°BeanFactoryå¢ï¼ä¹å°±æ¯è¯´å¨å®¹å¨å®ä¾å¯¹è±¡ä¸è®¿é®å®¹å¨æ¬èº«ï¼å¨springä¸æè¿æ ·ä¸ä¸ªBeanFactoryAwareæ¥å£ï¼å¨è¿ä¸ªæ¥å£æ个setBeanFactory(BeanFactory f)æ¹æ³ï¼æ们å¯ä»¥å®ç°è¯¥æ¥å£ï¼éåè¿ä¸ªæ¹æ³ï¼æ¥å¾å°æ们BeanFactoryï¼ä»ä¸å¾å°å¨æçå¾å°BeanFactoryä¸å®ä¾å¯¹è±¡ï¼ä½æ¯æ¾å°jbpmä¸handlerç±»ä¸æ¥ä½¿ç¨ï¼è¿æ¯æ æ³å®ç°çï¼å 为å¨è¿éå®ä¸æ¯æspringæ¥ç®¡ççï¼æ以å³ä½¿å®ç°BeanFactoryæ¥å£ï¼éåå ¶æ¹æ³ï¼ä½æ¯æ æ³å°BeanFactory设置ä¸å¼çï¼å 为å®æ¯ç±springæ¥ç®¡ççï¼æ以ææ æ³ä»ä¸ä¸ªä¸æ¯springæ管ççbeanä¸å»æ³¨å ¥springææä¾çbean对象ãä½æ¯æ们å¯ä»¥éè¿å¦ä¸ç§éå¾æ¥è§£å³è¿ä¸ªé®é¢ï¼å建ä¸ä¸ªè¾ å©ç±»BeanFactroyHelperç±»ï¼è®©å®æ¥å®ç°åæè¿ä¸ªBeanFactoryAwareæ¥å£ï¼å ·ä½å¦ä¸ï¼
Java代ç
public class BeanFactoryHelper implements BeanFactoryAware {
private static BeanFactory factory;
public void setBeanFactory(BeanFactory f) throws BeansException {
factory = f;
}
public static BeanFactory getFactory(){
return factory;
}
}
ç¶åï¼è®©ä¸é¢è¿ä¸ªç±»çº³å ¥springç管çï¼å¨springä¸é ç½®å¦ä¸ï¼
Java代ç
<bean id="beanFactoryHelper" class="com.oa.service.handler.BeanFactoryHelper">
</bean>
æåå¨æ们handlerç±»ä¸ï¼ç´æ¥ä½¿ç¨å°±å¯ä»¥äº
Java代ç
BeanFactory factory = BeanFactoryHelper.getFactory();
è¿ç§æ¹å¼å¯ä»¥ï¼ä½æ¯æ并éç¨è¿ç§æ¹å¼ï¼å 为第åç§æ¹å¼å·²ç»æ人ç»æåäºãæ以æ们就ä¸éè¦å¨éå¤åè¿äºç±»ä¼¼çå·¥ä½äºãæ以è¿ç§æ¹å¼æä¹ä¸ä¼éç¨ã
5ã 第äºç§æ¹å¼ï¼
éè¿ä¸é¢æ说çæ¹å¼ï¼å¨spring-modules.jarè¿ä¸ªç¬¬ä¸æ¹éæå å¼å人ä¸å·²ç»éç¨ç±»ä¼¼çæ¹å¼å®ç°äºãé£ä¹ä»ä»¬æ¯å¦ä½å®ç°çå¢ï¼è¿å°±éè¦æ¥äºè§£ä¸ä¸jbpmHandlerProxyçåºæ¬åçï¼å¨JbpmHandlerProxyç±»ä¸å®ç°äºActionHandler, AssignmentHandler, DecisionHandler, TaskControllerHandlerçæ¥å£ï¼å¨å®ç°ä¸åçæ¥å£ä¼è°ç¨ä¸åå®çä¸åçæ¹æ³executeãassignãdecideâ¦
ServiceLocator,å¨springä¸ä¹æä¾äºä¸ä¸ªServiceLocatorè¿ç§è®¾è®¡æ¨¡å¼çä¸ä¸ªæ¥å£BeanFactoryLocatorã BeanFactoryReferenceæ¥å£ï¼è¦æ³è¯¦ç»äºè§£å ¶å é¨æºå¶éè¦æ们è¿ä¸æ¥è±è´¹ç²¾åå»è§£æå ¶æºç äºãï¼å¨è¿éå°±ä¸è¯¦ç»å»åæäºï¼è¿éæåªæ¯äºè§£jbpmFactoryPorxyç±»ä¸å®ç°æºå¶ç大ä½ææ³,æ以ä¸é¢æå°±é对å¨ä»£çç±»ä¸çå ·ä½å®ç°ææ³å¤§ä½è¯´ä¸ä¸ï¼å¨JbpmHandlerProxyç±»ä¸å¾å°BeanFactory对象ï¼ä¸»è¦æ¯éè¿JbpmFactoryLocatoræ¥å¾å°BeanFactoryReferenceï¼éè¿BeanFactoryReferenceæ¥å¾å°Factoryãé£ä¹å¨JbpmHandlerProxyç±»ä¸çJbpmFactoryLocatoræ¯ä»åªéå¾å°çå¢ï¼æ¥çæºç å¯ä»¥å¾ç¥å¨å ¶JbpmFactoryLocatorç±»ä¸æ个setBeanFactoryï¼ï¼æ¹æ³ï¼é£ä¹è¿ä¸ªæ¹æ³æ¯æè°è°ç¨çå¢ï¼éè¿æ¥çå¾ç¥æ¯LocalJbpmConfigurationFactoryBeanç±»æ¥è°ç¨çã主è¦åæå¾å¦ä¸ï¼
以ä¸å°±jbpmFactoryProxyä¸å é¨æºå¶ã
ä¸é¢æå°±æ¥è¯´ä¸ä¸å ·ä½è§£å³æ¹æ¡æ¯ï¼
é¦å éè¿å©ç¨jbpmFactoryProxyçå®ç°ç±»ä¸retrieveBeanFactoryæ¹æ³çå ·ä½å®ç°æ¹å¼ï¼æ¥å¾å°jbpmä¸å·²ç»æ³¨å ¥çBeanFactory对象ï¼ä¸é¢æå°è¿ä¸æ¥è¿è¡å°è£ æ¥å®ç°èªå¨æ³¨å ¥çåè½ã
å è´´åºå¨jbpmçhandlerç±»ä¸çå ·ä½ä½¿ç¨,åå¨springä¸ä½¿ç¨Bean对象ä¸æ ·ä½¿ç¨ã
Java代ç
/**
* æ¯ç±BaseAutowireèªå¨æ³¨å ¥
*/
@Resource
private UserService userServce;
ä¸é¢ä¸æ®µä»£ç å°æ¯ææ½ååºæ¥çåºç±»ï¼
Java代ç
/**
* èªå¨æ³¨å ¥BeanFactoryåºç±»
* @author lzh
*
*/
public class BaseAutowire {
/**
* å¨è°ç¨åç±»çæ¶ä¼èªå¨è°ç¨
* å¨æé æ¹æ³ä¸è°ç¨retrieveBeanFactory()æ¹æ³å¾å°BeanFactory对象
* å©ç¨å®çå®ç°æ¥å£è®¾ç½®å°è¯¥èªèº«è®¾ç½®ä¸ºèªå¨æ³¨å ¥å°åç±»ä¸
*/
public BaseAutowire() {
((AutowireCapableBeanFactory)retrieveBeanFactory())
.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
}
protected BeanFactory retrieveBeanFactory() {
BeanFactoryLocator factoryLocator = new JbpmFactoryLocator();
BeanFactoryReference factory = factoryLocator.useBeanFactory(null);
if (factory == null)
throw new IllegalArgumentException("no beanFactory found under key=" + null);
try {
return factory.getFactory();
}
finally {
factory.release();
}
}
}
以ä¸æ¯æå¨å¦ä¹ jbpmæ¶æè®°å½ä¸ï¼å¸æè½å¤å¯¹ä»åçå·¥ä½èµ·å°ä¸å®ä½ç¨ã
driver does not support get/ set network timeout for connections什么意思?
Driver does not support get/set network timeout for connections错误的原因:pringboot 2.x默认的数据源变成了HikariPool了,弄了一个demo在使用数据源的码原时候系统报错 HikariPool-1 - Driver does not support get/set network timeout for connections. (null)。具体的码原解决办法:通过源码排查到连接验证有两种方式,一种是码原安卓进阶源码解析HikariPool自带的,具体逻辑没看,码原如果没适配对应的码原postfix 源码驱动就会报上面的错误;另一种是使用ConnectionTestQuery 这个属性来验证。那行代码大概就是码原:boolean isUseJdbc4Validation = getConnectionTestQuery == null;
如果这个属性没有配置,则使用默认的码原,若配置了,码原则使用自行配置的码原。所以只需要配置一下测试脚本即可。码原
扩展资料:
SpringBoot框架:
SpringBoot框架中还有两个非常重要的码原策略:开箱即用和约定优于配置。开箱即用,码原下线 源码Outofbox,码原是码原指在开发过程中,通过在MAVEN项目的pe 源码pom文件中添加相关依赖包,然后使用对应注解来代替繁琐的XML配置文件以管理对象的生命周期。这个特点使得开发人员摆脱了复杂的配置工作以及依赖的管理工作,更加专注于业务逻辑。hydra 源码
约定优于配置,Convention over configuration,是一种由SpringBoot本身来配置目标结构,由开发者在结构中添加信息的软件设计范式。这一特点虽降低了部分灵活性,增加了BUG定位的复杂性,但减少了开发人员需要做出决定的数量,同时减少了大量的XML配置,并且可以将代码编译、测试和打包等工作自动化。
百度百科-Spring Boot