为什么App Engine会阻止这个Spring代码?
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
Set<BeanDefinition> components = provider.findCandidateComponents("com/freshlyorc/datamodelbeans");
for (BeanDefinition component : components){
Class cls = Class.forName(component.getBeanClassName());
results.add(cls);
}
我每次在App Engine上运行此代码时都会说:
org.springframework.web.context.ContextLoader initWebApplicationContext: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'chapstick' defined in file [/base/data/home/apps/s~freshlyorc/1.00/WEB-INF/classes/com/freshlyorc/datamodelbeans/Chapstick.class]: Post-processing failed of bean type [class com.freshlyorc.datamodelbeans.Chapstick] failed; nested exception is com.google.apphosting.api.DeadlineExceededException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:835)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:493)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
ClassPathScanningCandidateComponentProvider
资源太重了吗?有更有效的替代方案吗?
答案 0 :(得分:0)
AppEngine仅允许列入白名单的库。 Spring库的这一部分现在可能在列表中。
答案 1 :(得分:0)
Google App Engine目前不允许任何请求完成超过60秒。抛出DeadlineExceededException告诉您时间到了。可以捕获异常以便自己花一些时间来清理任何松散的末端,但执行很快就会被杀死。
Spring执行的类路径扫描和反射确实是一个缓慢的过程。除非您在运行时添加到类路径,否则您应该在构建应用程序时执行此工作,将结果保存到稍后可以加载的文件中。