我试图通过Daemon服务运行Spring作为独立的应用程序。
我已经配置了run.sh脚本并将所有Spring jars框架添加到其中。
现在我正试图以这种方式从守护进程类中执行我的起点类:
代码: 公共类FeedDaemon实现守护进程 { 公共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来源-3.1.1.RELEASE.jar:$ FIXGW / LIB / org.springframework。 web.struts来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.web.servlet来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.web.portlet-来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.test来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.orm来源-3.1.1.RELEASE。罐子:$ FIXGW / lib目录/ org.springframework.jms来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.jdbc来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/组织.springframework.context.support来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.aspects来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.transaction来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.oxm来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.instrument来源,3.1.1.RELEASE.jar :$ FIXGW / lib目录/ org.springframework.instrument.tomcat来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/组织.springframework.expression来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.core来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.context来源-3.1 .1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.beans来源-3.1.1.RELEASE.jar:$ FIXGW / lib目录/ org.springframework.asm来源-3.1.1.RELEASE.jar:$ FIXGW / LIB / org.springframework.aop来源-3.1.1.RELEASE.jar:$ FIXGW / LIB /公地守护-1.0.3.jar
cd $ FIXGW /../jsvc-用户狐狸 -XX:+ DisableExplicitGC -XX:+ UseConcMarkSweepGC -XX:SurvivorRatio = 16 \ -Dlog4j.configuration = file:$ FIXGW / conf / log4j.properties \ -outfile / dev / null \ -errfile $ FIXGW / logs / error.log \ -verbose -classpath $ CLASSPATH \ com.spring.runner.FeedDaemon
有什么想法吗?
感谢, 射线。
答案 0 :(得分:1)
您似乎添加了包含Spring java源代码的所有jar(未编译代码)。您应该将未命名为......- sources ...的jar添加到类路径中。
答案 1 :(得分:0)
弹簧罐不在classpath中。检查我的answer。通过命令行在shellpath中添加所有库(在shell脚本中为ofcourse)。
我现在看到你的问题了。您在classpath中有源文件。这些被称为org.springframework.web.servlet-sources-3.1.1.RELEASE.jar
,而编译的罐子被称为org.springframework.web.servlet-3.1.1.RELEASE.jar