1

我正在尝试通过 Daemon 服务作为独立应用程序运行 Spring。

我已经配置了 run.sh 脚本并添加了所有 Spring jars 框架。

现在我正在尝试以这种方式从守护程序类执行我的起点类:

代码:公共类 FeedDaemon 实现守护进程 { public 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 脚本:

export 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.jarcore-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.jarcore-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

cd $FIXGW /../jsvc -user fox \ -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

任何的想法?

谢谢,雷。

4

2 回答 2

1

您似乎已经添加了所有包含 Spring java 源代码(未编译代码)的 jar。相反,您应该将未命名为 ...-sources... 的 jar 添加到类路径中。

于 2012-07-01T13:00:12.563 回答
0

弹簧罐不在类路径中。检查这个我的答案。通过命令行在类路径中添加所有库(当然在你的 shell 脚本中)。

好吧,我现在看到你的问题了。您在类路径中有源文件。这些被提及为org.springframework.web.servlet-sources-3.1.1.RELEASE.jar而编译的 jar 被提及为org.springframework.web.servlet-3.1.1.RELEASE.jar

于 2012-07-01T12:50:16.380 回答