2015-12-16 3 views
1

Я пытаюсь использовать контекст весны в простом приложении JMH (http://openjdk.java.net/projects/code-tools/jmh/), но при запуске benchmarks.jar, похоже, проблема с чтением документа схемы весны, хотя он работает на местном уровне.Использование Spring Beans в приложении JMH

Это стандартный проект jmh, созданный из базового архетипа maven. Для простоты ради:

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

// Весна конфигурации

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 

    <!-- spring beans --> 
</beans> 

При работе с основной есть Java -jar цель/benchmarks.jar без ошибок, но после того, как строить JMH убер баночку и работает

Java -jar мишень/benchmarks.jar

Я получаю следующее сообщение об ошибке

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'. 

Любые предложения?

+0

Вы можете разархивировать банку и может выглядеть, если springContext.xml там и содержит именно то, что вы определили? –

+0

Да, это в банке – joecoder

ответ

0

Фигурного это:

Добавления это мой Maven затененной банки плагин установил ее. H/T http://www.eorlovsky.com/2010/03/maven-shade-spring-core-handlers_27.html

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
<resource>META-INF/spring.handlers</resource> 
</transformer> 
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
<resource>META-INF/spring.schemas</resource> 
</transformer> 
Смежные вопросы