1

当我将 spring 与 smartfox 服务器一起使用时,出现错误:

Exception: java.lang.IllegalStateException
Message: Cannot load configuration class: com.lagente.sfs2x.AppConfig
Description: Extension initialization failed.
+--- --- ---+
Stack Trace:
+--- --- ---+
org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:410)
org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263)
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130)
org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:677)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:519)
org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
com.lagente.sfs2x.ExampleSFSZoneExtension.initAppContext(ExampleSFSZoneExtension.java:32)
com.lagente.sfs2x.ExampleSFSZoneExtension.init(ExampleSFSZoneExtension.java:26)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:433)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:249)
com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:266)
com.smartfoxserver.v2.Main.main(Main.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
com.install4j.runtime.launcher.Launcher.main(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

这是 AppConfig 类:

@Configuration
@ComponentScan({"com.lagente.sfs2x.*"})
public class AppConfig 
{
    @Bean
    public APIExtesion exampleExtension() {
        return new ExampleZoneExtension();
    }

    @Bean
    public ExtensionConfiguration extensionConfig() {
        return new ExtensionConfiguration();
    }
}

这是 ZoneExtension 的 init 函数中的源代码片段:

appContext = 
    new AnnotationConfigApplicationContext(AppConfig.class);

有人帮我解决吗?非常感谢。

4

1 回答 1

0

我有同样的问题,它是微不足道的,但有点棘手。Spring 无法加载您的配置类,因为它不在类路径中。我想你用 sfs2x-standalone 启动 Smartfox。它不会将SFS2X/extensions和子目录中的 jar 添加到类路径中。

因此,如果您将代码放入SFS2X/extensions/__lib__ ,则应该使用 sfs2x.bat。如果将代码放在SFS2X/extensions/my_extensions 之类的地方,则应编辑 sfs2x.bat 以将 my_extensions 添加到类路径中。

原来 sfs2x.bat 应该是

@..\jre\bin\java.exe -cp "./;lib/*;lib/jetty/lib/*;extensions/__lib__/*" -Dfile.encoding=UTF-8 -Xnoagent -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787 com.smartfoxserver.v2.Main %1 %2

将其更改为

@..\jre\bin\java.exe -cp "./;lib/*;lib/jetty/lib/*;extensions/__lib__/*;extensions/my_extension/*" -Dfile.encoding=UTF-8 -Xnoagent -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787 com.smartfoxserver.v2.Main %1 %2

它应该有帮助

于 2018-06-01T15:03:17.253 回答