NutzCN Logo
问答 关于NB与uflo集成的一点问题描述
发布于 2128天前 作者 shuxinyun 2004 次浏览 复制 上一个帖子 下一个帖子
标签:

在NB中集成了uflo正常,现在问题是是nutz的注入对象转化为AsSpringBean的问题,在spring4.2.3中:

/**
     * 容器初始化时,初始化Spring Mvc的Ioc容器,并放入ServletContext
     */
    public void contextInitialized(ServletContextEvent sce) {
        applicationContext = new XmlWebApplicationContext();
        applicationContext.setServletContext(sce.getServletContext());
        applicationContext.setConfigLocation(configLocation);
        applicationContext.refresh();
        appContext.getComboIocLoader().addLoader(new SpringIocLoader2(applicationContext, getSpringBeanNames().toArray(new String[0])));
        sce.getServletContext().setAttribute("spring." + selfName, applicationContext);
        // 登记所有标注了@AsSpringBean的对象到spring ioc
        Ioc ioc = appContext.getIoc();
        for (String name : ioc.getNamesByAnnotation(AsSpringBean.class)) {
            applicationContext.getBeanFactory().registerSingleton(name, ioc.get(null, name));
        }
    }

这个applicationContext.refresh();执行后,uflo中
下面这段代码执行,就是把所有bean转化成spring后缓存起来

@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		handerMap=new HashMap<String,Set<String>>();
		handerMap.put(NodeEventHandler.class.getSimpleName(), applicationContext.getBeansOfType(NodeEventHandler.class).keySet());
		handerMap.put(ProcessEventHandler.class.getSimpleName(), applicationContext.getBeansOfType(ProcessEventHandler.class).keySet());
		handerMap.put(DecisionHandler.class.getSimpleName(), applicationContext.getBeansOfType(DecisionHandler.class).keySet());
		handerMap.put(AssignmentHandler.class.getSimpleName(), applicationContext.getBeansOfType(AssignmentHandler.class).keySet());
		handerMap.put(ConditionHandler.class.getSimpleName(), applicationContext.getBeansOfType(ConditionHandler.class).keySet());
		handerMap.put(ActionHandler.class.getSimpleName(), applicationContext.getBeansOfType(ActionHandler.class).keySet());
		handerMap.put(ForeachHandler.class.getSimpleName(), applicationContext.getBeansOfType(ForeachHandler.class).keySet());
		handerMap.put(ReminderHandler.class.getSimpleName(), applicationContext.getBeansOfType(ReminderHandler.class).keySet());
		handerMap.put(CountersignHandler.class.getSimpleName(), applicationContext.getBeansOfType(CountersignHandler.class).keySet());
		handerMap.put(TaskListener.class.getSimpleName(), applicationContext.getBeansOfType(TaskListener.class).keySet());
		Set<String> set=new HashSet<String>();
		for(FormTemplateProvider provider:applicationContext.getBeansOfType(FormTemplateProvider.class).values()){
			set.add(provider.getFormTemplate());
		}
		handerMap.put(FormTemplateProvider.class.getSimpleName(), set);
	}

后面再加入新的bean后:
for (String name : ioc.getNamesByAnnotation(AsSpringBean.class)) {
applicationContext.getBeanFactory().registerSingleton(name, ioc.get(null, name));
}

uflo中这个缓存方法没有再执行,导致nutz注入转化的bean在uflo中找不到!看这个问题是否是我的理解错误还是可以调整下

9 回复

哪个bean呢?加AsSpringBean合区IocBean注解没


@IocBean(name = "uflo.processEvent") @AsSpringBean public class ProcessEvent implements ProcessEventHandler { @Override public void start(ProcessInstance processInstance, Context context) { } @Override public void end(ProcessInstance processInstance, Context context) { } }

我debug跟踪了下,这个已经识别了

就是这个setApplicationContext只执行一次,是在转化注册之前执行的,转化注册后就没有执行过!导致缓存变量中不包含这个转化的bean

/*******************************************************************************
 * Copyright 2017 Bstek
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.  You may obtain a copy
 * of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations under
 * the License.
 ******************************************************************************/
package com.bstek.uflo.console.handler.impl.list;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.bstek.uflo.console.handler.impl.WriteJsonServletHandler;
import com.bstek.uflo.process.handler.ActionHandler;
import com.bstek.uflo.process.handler.AssignmentHandler;
import com.bstek.uflo.process.handler.ConditionHandler;
import com.bstek.uflo.process.handler.CountersignHandler;
import com.bstek.uflo.process.handler.DecisionHandler;
import com.bstek.uflo.process.handler.ForeachHandler;
import com.bstek.uflo.process.handler.NodeEventHandler;
import com.bstek.uflo.process.handler.ProcessEventHandler;
import com.bstek.uflo.process.handler.ReminderHandler;
import com.bstek.uflo.process.listener.TaskListener;
import com.bstek.uflo.process.node.FormTemplateProvider;
import com.bstek.uflo.utils.EnvironmentUtils;

/**
 * @author Jacky.gao
 * @since 2016年12月8日
 */
public class HandlerListServletHandler extends WriteJsonServletHandler implements ApplicationContextAware{
	private Map<String,Set<String>> handerMap;
	private boolean debug;
	@Override
	public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String loginUser=EnvironmentUtils.getEnvironment().getLoginUser();
		if(loginUser==null && !debug){
			throw new IllegalArgumentException("Current run mode is not debug.");			
		}
		String handler=req.getParameter("handler");
		if(StringUtils.isEmpty(handler)){
			throw new IllegalArgumentException("Parameter handler can not be null");
		}
		writeObjectToJson(resp, handerMap.get(handler));
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		handerMap=new HashMap<String,Set<String>>();
		handerMap.put(NodeEventHandler.class.getSimpleName(), applicationContext.getBeansOfType(NodeEventHandler.class).keySet());
		handerMap.put(ProcessEventHandler.class.getSimpleName(), applicationContext.getBeansOfType(ProcessEventHandler.class).keySet());
		handerMap.put(DecisionHandler.class.getSimpleName(), applicationContext.getBeansOfType(DecisionHandler.class).keySet());
		handerMap.put(AssignmentHandler.class.getSimpleName(), applicationContext.getBeansOfType(AssignmentHandler.class).keySet());
		handerMap.put(ConditionHandler.class.getSimpleName(), applicationContext.getBeansOfType(ConditionHandler.class).keySet());
		handerMap.put(ActionHandler.class.getSimpleName(), applicationContext.getBeansOfType(ActionHandler.class).keySet());
		handerMap.put(ForeachHandler.class.getSimpleName(), applicationContext.getBeansOfType(ForeachHandler.class).keySet());
		handerMap.put(ReminderHandler.class.getSimpleName(), applicationContext.getBeansOfType(ReminderHandler.class).keySet());
		handerMap.put(CountersignHandler.class.getSimpleName(), applicationContext.getBeansOfType(CountersignHandler.class).keySet());
		handerMap.put(TaskListener.class.getSimpleName(), applicationContext.getBeansOfType(TaskListener.class).keySet());
		Set<String> set=new HashSet<String>();
		for(FormTemplateProvider provider:applicationContext.getBeansOfType(FormTemplateProvider.class).values()){
			set.add(provider.getFormTemplate());
		}
		handerMap.put(FormTemplateProvider.class.getSimpleName(), set);
	}
	
	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	@Override
	public String url() {
		return "/handlerlist";
	}
}

public void contextInitialized(ServletContextEvent sce) {
applicationContext = new XmlWebApplicationContext();
applicationContext.setServletContext(sce.getServletContext());
applicationContext.setConfigLocation(configLocation);
applicationContext.refresh();
appContext.getComboIocLoader().addLoader(new SpringIocLoader2(applicationContext, getSpringBeanNames().toArray(new String[0])));
sce.getServletContext().setAttribute("spring." + selfName, applicationContext);
// 登记所有标注了@AsSpringBean的对象到spring ioc
Ioc ioc = appContext.getIoc();
for (String name : ioc.getNamesByAnnotation(AsSpringBean.class)) {
applicationContext.getBeanFactory().registerSingleton(name, ioc.get(null, name));
}
applicationContext.refresh();//放到这里是是否可以解决问题,
}

额,你看看怎么改一下?

不好整,把refresh移到下面或复制到下面都报错!

按理说,遍历的时候应该能获取到的呀,package的问题?

日志里面ProcessEvent能看到被扫描到吗?

添加回复
请先登陆
回到顶部