Spring无法加载配置类

时间:2016-04-05 16:10:02

标签: spring smartfoxserver

当我在smartfox服务器上使用spring时出现错误:

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

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

1 个答案:

答案 0 :(得分: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

应该有帮助