2016-08-31 78 views
2

我正在嘗試遵循Arquillian示例的入門:http://arquillian.org/guides/getting_started/ 我正在使用eclipse Luna。我pom.xml嘗試運行Arquillian入門示例時CDI api版本不匹配錯誤

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>org.arquillian.example</groupId> 
    <artifactId>arquillian-tutorial</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>arquillian-tutorial</name> 
    <url>http://arquillian.org/guides/getting_started/</url> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.12</version> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.jboss.arquillian</groupId> 
       <artifactId>arquillian-bom</artifactId> 
       <version>1.0.0.Final</version> 
       <scope>import</scope> 
       <type>pom</type> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.jboss.spec</groupId> 
      <artifactId>jboss-javaee-6.0</artifactId> 
      <version>1.0.0.Final</version> 
      <type>pom</type> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.arquillian.junit</groupId> 
      <artifactId>arquillian-junit-container</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.arquillian.container</groupId> 
      <artifactId>arquillian-weld-ee-embedded-1.1</artifactId> 
      <version>1.0.0.CR9</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.weld</groupId> 
      <artifactId>weld-core</artifactId> 
      <version>2.3.5.Final</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-simple</artifactId> 
      <version>1.6.4</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

當執行測試,我結束了以下錯誤:

org.jboss.weld.exceptions.IllegalStateException: WELD-000144: CDI API version mismatch. CDI 1.0 API detected on classpath. Weld requires version 1.1 or better. 
    at org.jboss.weld.bootstrap.WeldStartup.checkApiVersion(WeldStartup.java:242) 
    at org.jboss.weld.bootstrap.WeldStartup.startContainer(WeldStartup.java:175) 
    at org.jboss.weld.bootstrap.WeldBootstrap.startContainer(WeldBootstrap.java:69) 
    at org.jboss.weld.bootstrap.WeldBootstrap.startContainer(WeldBootstrap.java:64)   

我怎樣才能解決這個問題 - 最好用焊接包的舊版本,因爲我不能夠改變我的開發環境設置。

回答

1

添加以下依賴到pom.xml的解決了這個問題:

<dependency> 
     <groupId>javax.enterprise</groupId> 
     <artifactId>cdi-api</artifactId> 
     <version>1.2</version> 
    </dependency> 
+0

這只是覆蓋來自另一個依賴關係,看看我的答案和更新指南。 –

0

它在指南中得到糾正已經,你必須改變

<dependency> 
    <groupId>org.jboss.spec</groupId> 
    <artifactId>jboss-javaee-6.0</artifactId> 
    <version>1.0.0.Final</version> 
    <type>pom</type> 
    <scope>provided</scope> 
</dependency> 

<dependency> 
    <groupId>org.jboss.spec</groupId> 
    <artifactId>jboss-javaee-7.0</artifactId> 
    <version>1.0.3.Final</version> 
    <type>pom</type> 
    <scope>provided</scope> 
</dependency> 
+0

是的,看起來更正確的解決方案。 – jirit

相關問題