# How to write es plugin with spring framework

**URL:** <https://discuss.elastic.co/t/how-to-write-es-plugin-with-spring-framework/96417>\
**Category:** Elasticsearch\
**Created:** [August 9, 2017, 10:15am UTC](https://discuss.elastic.co/t/how-to-write-es-plugin-with-spring-framework/96417 "2017-08-09T10:15:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![371c6d055967023937c8](https://avatars.discourse-cdn.com/v4/letter/3/a698b9/32.png) [@371c6d055967023937c8](https://discuss.elastic.co/u/371c6d055967023937c8)\
**Post date:** [August 9, 2017, 10:15am UTC](https://discuss.elastic.co/t/how-to-write-es-plugin-with-spring-framework/96417/1 "2017-08-09T10:15:50Z")

</div>

I'm writing a analyze plugin, it reads keywords from database, and synchronize new words every several minutes.  
I use spring framework as a dependency.  
My test program runs fine. But when I install my plugin into elasticsearch, it runs into error:  
`Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.jiurong.search.plugin.AppConfig]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/context/annotation/AutoProxyRegistrar.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:548) ~[?:?_]`  
It seems when spring use some of it's classloader to load class, the class is not on the classpath. Is there some way I can use spring framework in a es plugin?

---

<div class="post-metadata">

**Author:** ![371c6d055967023937c8](https://avatars.discourse-cdn.com/v4/letter/3/a698b9/32.png) [@371c6d055967023937c8](https://discuss.elastic.co/u/371c6d055967023937c8)\
**Post date:** [August 10, 2017, 1:37am UTC](https://discuss.elastic.co/t/how-to-write-es-plugin-with-spring-framework/96417/2 "2017-08-10T01:37:51Z")

</div>

Spring framework use classloader to load classes and some resources. Override it's default classloader to plugin classloader, and run it's code inside AccessController.doPrivilige method, it will work.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 7, 2017, 1:37am UTC](https://discuss.elastic.co/t/how-to-write-es-plugin-with-spring-framework/96417/3 "2017-09-07T01:37:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
