我有一个在Eclipse中运行良好的Red5应用程序。但是,当我构建应用程序并尝试将其作为Windows服务运行时,我收到错误。
应用程序启动后,当它尝试启动Red5服务器时,我收到以下错误/堆栈跟踪:
Tue Mar 14 16:00:51 MDT 2017: debug: about to get baseLoader
Tue Mar 14 16:00:51 MDT 2017: debug: about to get loader: sun.misc.Launcher$AppClassLoader@1bb3e9a
Tue Mar 14 16:00:51 MDT 2017: debug: about to set new loader:java.net.URLClassLoader@d16e55
Tue Mar 14 16:00:51 MDT 2017: debug: about to create boot object: java.net.URLClassLoader@d16e55
Tue Mar 14 16:00:51 MDT 2017: debug: about to get method 1: org.red5.server.Launcher@b20dae
Tue Mar 14 16:00:51 MDT 2017: debug: about to invoke method 1: public void org.red5.server.Launcher.launch() throws java.lang.Exception
Tue Mar 14 16:01:01 MDT 2017: error: Errorjava.lang.reflect.InvocationTargetException
Tue Mar 14 16:01:01 MDT 2017: error: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at ...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.rzo.yajsw.app.WrapperJVMMain.executeMain(WrapperJVMMain.java:53)
at org.rzo.yajsw.app.WrapperJVMMain.main(WrapperJVMMain.java:36)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'context.loader' defined in class path resource [red5.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcat.server' defined in class path resource [jee-container.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.red5.server.Launcher.launch(Launcher.java:69)
... 14 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcat.server' defined in class path resource [jee-container.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:217)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:350)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
at org.red5.server.ContextLoader.afterPropertiesSet(ContextLoader.java:113)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 24 more
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Unknown Source)
at java.util.Properties.setProperty(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at org.red5.server.tomcat.TomcatLoader.start(TomcatLoader.java:252)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1702)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1641)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 36 more
我的相关代码如下:
// get current loader
logDebug(" about to get baseLoader");
ClassLoader baseLoader = Thread.currentThread().getContextClassLoader();
// build a ClassLoader
logDebug(" about to get loader: " + baseLoader);
ClassLoader loader = ClassLoaderBuilder.build();
// set new loader as the loader for this thread
logDebug(" about to set new loader:" + loader);
Thread.currentThread().setContextClassLoader(loader);
// create a new instance of this class using new classloader
logDebug(" about to create boot object: " + loader);
Object boot = Class.forName("org.red5.server.Launcher", true, loader).newInstance();
logDebug(" about to get method 1: " + boot);
Method m1 = boot.getClass().getMethod("launch", (Class[]) null);
logDebug(" about to invoke method 1: " + m1);
m1.invoke(boot, (Object[]) null);
// not that it matters, but set it back to the original loader
logDebug(" about to set original loader: " + m1);
Thread.currentThread().setContextClassLoader(baseLoader);
有什么想法导致错误以及如何解决错误?
编辑:
我添加了一个名为red5.root的系统属性设置到Red5根目录,如下所示,它摆脱了我上面的nullPointerException。
String red5Root = serverHome + "/red5-server-1.0.6-RELEASE";
System.setProperty("red5.root", red5Root);
但是我仍然无法连接到red5服务器。当我尝试使用以下网址访问我的网络应用时:
localhost:8080 / streaming / streaming.html
我遇到这个例外的500错误:
显示java.lang.NullPointerException org.red5.logging.LoggerContextFilter.doFilter(LoggerContextFilter.java:64)
可能导致此NullPointerExeption的原因是什么?
答案 0 :(得分:0)
由于第一个问题已在编辑中得到回答,我将回答第二个问题。
由于类路径中的日志记录jar冲突,NPE正在发生。我可以通过从 webapps / myApp / WEB-INF / web.xml 文件中删除以下内容来解决问题。
<filter>
<filter-name>LoggerContextFilter</filter-name>
<filter-class>org.red5.logging.LoggerContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggerContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>