title: Using Spring Beans in a JMH Application
body: <p>I'm trying to use a spring context in a simple JMH application (<a href="http://openjdk.java.net/projects/code-tools/jmh/" rel="nofollow">http://openjdk.java.net/projects/code-tools/jmh/</a>), but when running the benchmarks.jar it seems to have trouble reading the spring schema document even though though it works locally. </p>
  
  <p>It's a standard jmh project set up from the base maven archetype. For simplicity sake:</p>
  
  <pre><code>package org.sample;
  
  import org.openjdk.jmh.annotations.Benchmark;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class BenchmarkTest {
  
  public BenchmarkTest() {
      ApplicationContext context = new ClassPathXmlApplicationContext("springContext.xml");
  }
  
  @Benchmark
  public void benchmarkSomething() {
      // BENCHMARKS
  }
  
  public static void main(String [] args) {
      BenchmarkTest benchmarkTest = new BenchmarkTest();
      benchmarkTest.benchmarkSomething();
   }
  }
  </code></pre>
  
  <p>//Spring config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans.xsd
                             http://www.springframework.org/schema/context
                             http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;!-- spring beans --&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>When running from main there are java -jar target/benchmarks.jar
  no errors, but after building the jmh uber jar and running </p>
  
  <blockquote>
    <p>java -jar target/benchmarks.jar</p>
  </blockquote>
  
  <p>I get the following error </p>
  
  <pre><code>org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from class path resource [springContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 80; cvc-elt.1: Cannot find the declaration of element 'beans'.
  </code></pre>
  
  <p>Any suggestions? </p>