我试图通过Daemon服务运行Spring作为课程的独立应用程序。
我已经配置了run.sh脚本,并将其添加到所有Spring jar框架中。
现在,我试图以这种方式从Daemon类执行我的起点类:
码:
公共类FeedDaemon实现Daemon
{
公共FeedDaemon()
{
}
protected final static Logger log = LoggerFactory.getLogger(FeedDaemon.class);
protected boolean shouldBeRunning = false;
protected ProviderFactory runner = null;
@Override
public void destroy()
{
runner = null;
}
@Override
public void init(DaemonContext arg0) throws Exception
{
runner = new ProviderFactory();
}
public void start() throws RuntimeError, ConfigError
{
log.info("Starting daemon");
runner.start();
}
public void stop() throws Exception
{
log.info("Starting Shutting daemon ...");
runner.stop();
}
}
码:
package com.spring.test;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.spring.aspect.Spring3HelloWorld;
import com.spring.beans.ParkingCar.CarBean;
import com.spring.beans.ParkingCar.CarMaker;
import com.spring.beans.ParkingCar.FourWheelsVechile;
import com.spring.beans.ParkingCar.TwoWheelsVechile;
import com.spring.beans.ParkingCar.Vechile;
import com.spring.beans.ParkingCar.VechileDetails;
import com.spring.beans.calculator.CalculateNumbersHolderBean;
import com.spring.beans.calculator.CalculateStrategyBean;
import com.spring.beans.calculator.CalculatorBean;
public class Spring3HelloWorldTest
{
static Logger logger = Logger.getLogger(Spring3HelloWorldTest.class);
public static void execute()
{
try
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
logger.debug("3");
Vechile fourWheelsVechile = (FourWheelsVechile) context.getBean("Ambulance");
fourWheelsVechile.drive();
CarMaker carMaker = (CarMaker) context.getBean("carMaker");
CarBean carBean = carMaker.createNewCar();
carBean.driveCar();
}
catch (Throwable e)
{
logger.error(e);
}
}
}
我得到这个错误:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:164)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at com.spring.runner.FeedDaemon.init(FeedDaemon.java:37)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 6 more
Cannot load daemon
Service exit with a return value of 3
多数民众赞成在我的run.sh脚本:
导出JAVA_HOME = / .. /
FIXGW = / .. / FIXGW
CLASSPATH = $ FIXGW / lib / FeedHandler.jar:$ FIXGW / lib / FixSpring.jar:$ FIXGW / lib / org.springframework.web-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework。 web.struts-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.web.servlet-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.web.portlet- sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.test-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.orm-sources-3.1.1.RELEASE。 jar:$ FIXGW / lib / org.springframework.jms-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.jdbc-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org .springframework.context.support-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.aspects-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.transaction-sources -3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.oxm-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.instrument-sources-3.1.1.RELEASE.jar :$ FIXGW / lib / org.springframework.instrument.tomcat-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org .springframework.expression-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.core-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.context-sources-3.1 .1.RELEASE.jar:$ FIXGW / lib / org.springframework.beans-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.asm-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / org.springframework.aop-sources-3.1.1.RELEASE.jar:$ FIXGW / lib / commons-daemon-1.0.3.jar
光盘$ FIXGW
/../jsvc -user fox \
-XX:+ DisableExplicitGC -XX:+ UseConcMarkSweepGC -XX:SurvivorRatio = 16 \
-Dlog4j.configuration =文件:$ FIXGW / conf / log4j.properties \
-outfile / dev / null \
-errfile $ FIXGW / logs / error.log \
-verbose -classpath $ CLASSPATH \
com.spring.runner.FeedDaemon
任何想法?
谢谢,
射线。
最佳答案
弹簧罐不在类路径中。检查我的answer。通过命令行(在shell脚本中当然)将所有库添加到类路径中。
好吧,我现在看到你的问题了。您在classpath中有源文件。这些被称为org.springframework.web.servlet-sources-3.1.1.RELEASE.jar
,而已编译的jar被称为org.springframework.web.servlet-3.1.1.RELEASE.jar