我试图在karaf上运行Spring。
当我试图运行时:
public class SnifferActivator implements BundleActivator {
@Override
public void start(BundleContext bundleContext) throws Exception {
System.out.println("Start");
new Thread(new Sniffer()).start();
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
}
}
public class Sniffer implements Runnable{
@Override
public void run() {
ApplicationContext context = new AnnotationConfigApplicationContext(SnifferConfig.class);
}
}
我收到以下错误消息:
karaf@root()> Exception in thread "Thread-305" java.lang.IllegalStateException:
Cannot load configuration class: com.emot.worker.configuration.SnifferConfig
at org.springframework.context.annotation.ConfigurationClassPostProcesso
r.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403)
at
我检查了我在Karaf上部署的包,这个类就在那里。
答案 0 :(得分:1)
当我尝试将Spring 4.x用于Karaf 4中的捆绑包时,我遇到了同样的问题,因为捆绑包没有导入所有Spring包,可能是插件&# 34;行家束-插件"基于语法分析导出必要的包,并通过反射在运行时弹出许多类。这些是我的步骤:
在Karaf 4.x中安装Spring 4.x
列出弹簧束导出的包
将包(如果需要,带有版本)添加到" Import-Package"在您的pom中的插件maven-bundle-plugin的配置中。在我的例子中,我从spring-core / spring-context / spring-beans导入了所有包。这样,你的bundle会导入所有的包,所以我知道我在我的poc中添加了比我需要的更多的包,但是它& #39;在运行时通过反射加载spring类时,很难确定应用程序将在所有场景中使用的所有spring包。
<Import-Package>org.springframework.asm;version=4.3.12.RELEASE, org.springframework.cglib;version=4.3.12.RELEASE, org.springframework.cglib.beans;version=4.3.12.RELEASE, org.springframework.cglib.core;version=4.3.12.RELEASE, org.springframework.cglib.core.internal;version=4.3.12.RELEASE,
org.springframework.cglib.proxy;version=4.3.12.RELEASE, org.springframework.cglib.reflect;version=4.3.12.RELEASE, org.springframework.cglib.transform;version=4.3.12.RELEASE, org.springframework.cglib.transform.impl;version=4.3.12.RELEASE, org.springframework.cglib.util;version=4.3.12.RELEASE,
org.springframework.core;version=4.3.12.RELEASE, org.springframework.core.annotation;version=4.3.12.RELEASE, org.springframework.core.convert;version=4.3.12.RELEASE, org.springframework.core.convert.converter;version=4.3.12.RELEASE, org.springframework.core.convert.support;version=4.3.12.RELEASE,
org.springframework.core.env;version=4.3.12.RELEASE, org.springframework.core.io;version=4.3.12.RELEASE, org.springframework.core.io.support;version=4.3.12.RELEASE, org.springframework.core.serializer;version=4.3.12.RELEASE, org.springframework.core.serializer.support;version=4.3.12.RELEASE,
org.springframework.core.style;version=4.3.12.RELEASE, org.springframework.core.task;version=4.3.12.RELEASE, org.springframework.core.task.support;version=4.3.12.RELEASE, org.springframework.core.type;version=4.3.12.RELEASE, org.springframework.core.type.classreading;version=4.3.12.RELEASE,
org.springframework.core.type.filter;version=4.3.12.RELEASE, org.springframework.lang;version=4.3.12.RELEASE, org.springframework.objenesis;version=4.3.12.RELEASE, org.springframework.objenesis.instantiator;version=4.3.12.RELEASE, org.springframework.objenesis.instantiator.android;version=4.3.12.RELEASE,
org.springframework.objenesis.instantiator.annotations;version=4.3.12.RELEASE, org.springframework.objenesis.instantiator.basic;version=4.3.12.RELEASE, org.springframework.objenesis.instantiator.gcj;version=4.3.12.RELEASE, org.springframework.objenesis.instantiator.perc;version=4.3.12.RELEASE,
org.springframework.objenesis.instantiator.sun;version=4.3.12.RELEASE, org.springframework.objenesis.instantiator.util;version=4.3.12.RELEASE, org.springframework.objenesis.strategy;version=4.3.12.RELEASE, org.springframework.util;version=4.3.12.RELEASE,
org.springframework.util.backoff;version=4.3.12.RELEASE, org.springframework.util.comparator;version=4.3.12.RELEASE, org.springframework.util.concurrent;version=4.3.12.RELEASE, org.springframework.util.xml;version=4.3.12.RELEASE, org.springframework.beans;version=4.3.12.RELEASE,
org.springframework.beans.annotation;version=4.3.12.RELEASE, org.springframework.beans.factory;version=4.3.12.RELEASE, org.springframework.beans.factory.access;version=4.3.12.RELEASE, org.springframework.beans.factory.access.el;version=4.3.12.RELEASE,
org.springframework.beans.factory.annotation;version=4.3.12.RELEASE, org.springframework.beans.factory.config;version=4.3.12.RELEASE, org.springframework.beans.factory.groovy;version=4.3.12.RELEASE, org.springframework.beans.factory.parsing;version=4.3.12.RELEASE,
org.springframework.beans.factory.serviceloader;version=4.3.12.RELEASE, org.springframework.beans.factory.support;version=4.3.12.RELEASE, org.springframework.beans.factory.wiring;version=4.3.12.RELEASE, org.springframework.beans.factory.xml;version=4.3.12.RELEASE,
org.springframework.beans.propertyeditors;version=4.3.12.RELEASE, org.springframework.beans.support;version=4.3.12.RELEASE, org.springframework.cache;version=4.3.12.RELEASE, org.springframework.cache.annotation;version=4.3.12.RELEASE, org.springframework.cache.concurrent;version=4.3.12.RELEASE,
org.springframework.cache.config;version=4.3.12.RELEASE, org.springframework.cache.interceptor;version=4.3.12.RELEASE, org.springframework.cache.support;version=4.3.12.RELEASE, org.springframework.context;version=4.3.12.RELEASE, org.springframework.context.access;version=4.3.12.RELEASE,
org.springframework.context.annotation;version=4.3.12.RELEASE, org.springframework.context.config;version=4.3.12.RELEASE, org.springframework.context.event;version=4.3.12.RELEASE, org.springframework.context.expression;version=4.3.12.RELEASE, org.springframework.context.i18n;version=4.3.12.RELEASE,
org.springframework.context.support;version=4.3.12.RELEASE, org.springframework.context.weaving;version=4.3.12.RELEASE, org.springframework.ejb.access;version=4.3.12.RELEASE, org.springframework.ejb.config;version=4.3.12.RELEASE, org.springframework.ejb.interceptor;version=4.3.12.RELEASE,
org.springframework.format;version=4.3.12.RELEASE, org.springframework.format.annotation;version=4.3.12.RELEASE, org.springframework.format.datetime;version=4.3.12.RELEASE, org.springframework.format.datetime.joda;version=4.3.12.RELEASE, org.springframework.format.datetime.standard;version=4.3.12.RELEASE,
org.springframework.format.number;version=4.3.12.RELEASE, org.springframework.format.number.money;version=4.3.12.RELEASE, org.springframework.format.support;version=4.3.12.RELEASE, org.springframework.instrument.classloading;version=4.3.12.RELEASE,
org.springframework.instrument.classloading.glassfish;version=4.3.12.RELEASE, org.springframework.instrument.classloading.jboss;version=4.3.12.RELEASE, org.springframework.instrument.classloading.tomcat;version=4.3.12.RELEASE, org.springframework.instrument.classloading.weblogic;version=4.3.12.RELEASE,
org.springframework.instrument.classloading.websphere;version=4.3.12.RELEASE, org.springframework.jmx;version=4.3.12.RELEASE, org.springframework.jmx.access;version=4.3.12.RELEASE, org.springframework.jmx.export;version=4.3.12.RELEASE, org.springframework.jmx.export.annotation;version=4.3.12.RELEASE,
org.springframework.jmx.export.assembler;version=4.3.12.RELEASE, org.springframework.jmx.export.metadata;version=4.3.12.RELEASE, org.springframework.jmx.export.naming;version=4.3.12.RELEASE, org.springframework.jmx.export.notification;version=4.3.12.RELEASE,
org.springframework.jmx.support;version=4.3.12.RELEASE, org.springframework.jndi;version=4.3.12.RELEASE, org.springframework.jndi.support;version=4.3.12.RELEASE, org.springframework.remoting;version=4.3.12.RELEASE, org.springframework.remoting.rmi;version=4.3.12.RELEASE,
org.springframework.remoting.soap;version=4.3.12.RELEASE, org.springframework.remoting.support;version=4.3.12.RELEASE, org.springframework.scheduling;version=4.3.12.RELEASE, org.springframework.scheduling.annotation;version=4.3.12.RELEASE, org.springframework.scheduling.concurrent;version=4.3.12.RELEASE,
org.springframework.scheduling.config;version=4.3.12.RELEASE, org.springframework.scheduling.support;version=4.3.12.RELEASE, org.springframework.scripting;version=4.3.12.RELEASE, org.springframework.scripting.bsh;version=4.3.12.RELEASE, org.springframework.scripting.config;version=4.3.12.RELEASE,
org.springframework.scripting.groovy;version=4.3.12.RELEASE, org.springframework.scripting.jruby;version=4.3.12.RELEASE, org.springframework.scripting.support;version=4.3.12.RELEASE, org.springframework.stereotype;version=4.3.12.RELEASE, org.springframework.ui;version=4.3.12.RELEASE,
org.springframework.ui.context;version=4.3.12.RELEASE, org.springframework.ui.context.support;version=4.3.12.RELEASE, org.springframework.validation;version=4.3.12.RELEASE, org.springframework.validation.annotation;version=4.3.12.RELEASE, org.springframework.validation.beanvalidation;version=4.3.12.RELEASE,
org.springframework.validation.support;version=4.3.12.RELEASE, org.springframework.cache.caffeine;version=4.3.12.RELEASE, org.springframework.cache.ehcache;version=4.3.12.RELEASE, org.springframework.cache.guava;version=4.3.12.RELEASE, org.springframework.cache.jcache;version=4.3.12.RELEASE,
org.springframework.cache.jcache.config;version=4.3.12.RELEASE, org.springframework.cache.jcache.interceptor;version=4.3.12.RELEASE, org.springframework.cache.transaction;version=4.3.12.RELEASE, org.springframework.mail;version=4.3.12.RELEASE, org.springframework.mail.javamail;version=4.3.12.RELEASE,
org.springframework.scheduling.commonj;version=4.3.12.RELEASE, org.springframework.scheduling.quartz;version=4.3.12.RELEASE, org.springframework.ui.freemarker;version=4.3.12.RELEASE, org.springframework.ui.jasperreports;version=4.3.12.RELEASE, org.springframework.ui.velocity;version=4.3.12.RELEASE,
org.springframework.expression;version=4.3.12.RELEASE, org.springframework.expression.common;version=4.3.12.RELEASE, org.springframework.expression.spel;version=4.3.12.RELEASE, org.springframework.expression.spel.ast;version=4.3.12.RELEASE, org.springframework.expression.spel.generated;version=4.3.12.RELEASE,
org.springframework.expression.spel.standard;version=4.3.12.RELEASE, org.springframework.expression.spel.support;version=4.3.12.RELEASE, org.springframework.aop;version=4.3.12.RELEASE, org.springframework.aop.aspectj;version=4.3.12.RELEASE, org.springframework.aop.aspectj.annotation;version=4.3.12.RELEASE,
org.springframework.aop.aspectj.autoproxy;version=4.3.12.RELEASE, org.springframework.aop.config;version=4.3.12.RELEASE, org.springframework.aop.framework;version=4.3.12.RELEASE, org.springframework.aop.framework.adapter;version=4.3.12.RELEASE, org.springframework.aop.framework.autoproxy;version=4.3.12.RELEASE,
org.springframework.aop.framework.autoproxy.target;version=4.3.12.RELEASE, org.springframework.aop.interceptor;version=4.3.12.RELEASE, org.springframework.aop.scope;version=4.3.12.RELEASE, org.springframework.aop.support;version=4.3.12.RELEASE, org.springframework.aop.support.annotation;version=4.3.12.RELEASE,
org.springframework.aop.target;version=4.3.12.RELEASE, org.springframework.aop.target.dynamic;version=4.3.12.RELEASE</Import-Package>
&#13;
有了这个,你的bundle可以使用spring 4.x,但是你必须手动创建应用程序上下文,我使用参数&#34; init-method&#34;在蓝图定义中的bean的定义中,我不喜欢它,但无论如何,它都有效,我正在寻找一种更优雅的方式。
PD:抱歉我的英文。