Error creating bean with name jbpmConfiguration

来源:互联网 发布:望远镜放大倍数 知乎 编辑:程序博客网 时间:2024/06/06 04:56

写了一个spring的jbpmConfiguration

package com.aceway.adf.workflow;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.persistence.db.DbPersistenceServiceFactory;
import org.jbpm.svc.Services;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

public class LocalJbpmConfigurationFactoryBean implements InitializingBean,
  DisposableBean, FactoryBean, BeanFactoryAware, BeanNameAware {

 private JbpmConfiguration jbpmConfiguration;

 private String contextName = JbpmContext.DEFAULT_JBPM_CONTEXT_NAME;

 public void destroy() throws Exception {
  if (jbpmConfiguration != null) {
   jbpmConfiguration.close();
  }
 }

 /**
  * FactoryLocator
  */
 private JbpmFactoryLocator factoryLocator = new JbpmFactoryLocator();

 /**
  * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
  */
 public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
  factoryLocator.setBeanFactory(beanFactory);

 }

 /**
  * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
  */
 public void setBeanName(String name) {
  factoryLocator.setBeanName(name);
 }

 public void afterPropertiesSet() throws Exception {
  jbpmConfiguration = JbpmConfiguration.getInstance();
  DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) jbpmConfiguration
    .getServiceFactory(Services.SERVICENAME_PERSISTENCE);
 }

 /**
  * @see org.springframework.beans.factory.FactoryBean#getObject()
  */
 public Object getObject() throws Exception {
  return jbpmConfiguration;
 }

 /**
  * @see org.springframework.beans.factory.FactoryBean#getObjectType()
  */
 public Class getObjectType() {
  return JbpmConfiguration.class;
 }

 /**
  * @see org.springframework.beans.factory.FactoryBean#isSingleton()
  */
 public boolean isSingleton() {
  return true;
 }

 public String getContextName() {
  return contextName;
 }

 public void setContextName(String contextName) {
  this.contextName = contextName;
 }
}

 

在配制文件里写入

<bean id="jbpmConfiguration" class="com.aceway.adf.workflow.LocalJbpmConfigurationFactoryBean"></bean>

 

 <bean id="jbpmAdminServices" class="com.aceway.adf.workflow.service.AdminServicesImpl">
  <property name="jbpmConfiguration">
   <ref bean="jbpmConfiguration" />
  </property>
 </bean>

 

在java文件里写入

private JbpmConfiguration jbpmConfiguration;

 

 public JbpmConfiguration getJbpmConfiguration() {
  return jbpmConfiguration;
 }

 public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
  this.jbpmConfiguration = jbpmConfiguration;
 }

 

这样的话tomcat是可以起来的.但是一执行页面的时候,就会出现

 Error creating bean with name 'jbpmConfiguration' defined in ServletContext resource [/WEB-INF/workflowsystem-servlet.xml]

 

问题正待解决...............

 

-----------------------------------------------------------------------------

问题已经解决

主要是因为在workflowsystem-servlet.xml文件里写成<beans default-autowire="autodetect">将它去掉就可以了.

So far you’ve seen how to wire all of your bean’s properties explicitly using the <property> element. Alternatively, you can have Spring wire them automatically autowire property on each <bean> that you want autowired:

 

default-autowire有四种属性:

byName—Attempts to find a bean in the container whose name (or ID) is the same as the name of the property being wired. If a matching bean is not found, then the property will remain unwired.
byType—Attempts to find a single bean in the container whose type matches the type of the property being wired. If no matching bean is found, then the property will not be wired. If more than one bean matches, an org.springrframework.beans.factory.UnsatisfiedDependencyExcpetion will be thrown.
constructor—Tries to match up one or more beans in the container with the parameters of one of the constructors of the bean being wired. In the event of ambiguous beans or ambiguous constructors, an
org.springframework.beans.factory.UnsatisfiedDependencyException will be thrown.
autodetect—Attempts to autowire by constructor first and then using
byType. Ambiguity is handled the same way as with constructor and
byType wiring.

摘自<<spring in action>>

 

 

原创粉丝点击