1

When I use spring with smartfox server I get an error:

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)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Here's AppConfig class:

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

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

and here's source code snippet in ZoneExtension's init function:

appContext = 
    new AnnotationConfigApplicationContext(AppConfig.class);

Anyone help me resolve it? Thank so much.

dung ta van
  • 988
  • 8
  • 13

1 Answers1

0

I had that same issue, it's trivial, but a little bit tricky. Spring can't load your configuration class because it's not in the classpath. I suppose you start Smartfox with sfs2x-standalone. It doesn't add jars from SFS2X/extensions and subdirectories to classpath.

So you should use sfs2x.bat if you put your code to SFS2X/extensions/__lib__. If you put your code somewhere like SFS2X/extensions/my_extensions, you should edit sfs2x.bat to add my_extensions to classpath.

Originally sfs2x.bat should be

@..\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

Change it to

@..\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

It should help

Ilya Sazonov
  • 1,006
  • 10
  • 16