Mybatis cdi javaSE没有注入@Mapper

时间:2017-04-24 09:14:14

标签: java maven cdi mybatis mybatis-cdi

我正在尝试使用mybatis-cdi设置一个独立的javaSE应用程序(不在j2ee容器中),但是使用焊接。

日志告诉我找到@Mapper UserMapper:

11:04:15.750 TRACE [Thread-1]  o.j.w.Bootstrap - Sending PAT using the fast event resolver: [BackedAnnotatedType] public abstract interface @Mapper class com.XXX.XXX.XXX.persistence.mapper.UserMapper
Apr 24, 2017 11:04:15 AM org.mybatis.cdi.MybatisExtension processAnnotatedType
INFO: MyBatis CDI Module - Found class with @Mapper-annotation: UserMapper

我的mybatis映射器:

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import com.consultia.ferrer.socketserver.model.orm.User;

@org.mybatis.cdi.Mapper
//@org.apache.ibatis.annotations.Mapper
public interface UserMapper {

   @ResultType(User.class)
   @Select("SELECT * FROM user WHERE user=#{user}")
   User findBy(@Param("user") String user);

}

但在我的对象注入结果为null:

public class MainController implements ILogger {

       @Inject
       private UserMapper userMapper; //TODO INJECTION DON'T WORK

使用的依赖关系:

http://maven.apache.org/xsd/maven-4.0.0.xsd">     [...]     

    <!-- CDI ====================================================== -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.weld.se/weld-se-core -->
    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se</artifactId>
        <version>2.4.3.Final</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.enterprise/cdi-api -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.transaction</groupId>
      <artifactId>jboss-transaction-api_1.2_spec</artifactId>
      <version>1.0.0.Final</version>
      <scope>provided</scope>
    </dependency>       
    <!-- https://mvnrepository.com/artifact/org.jboss/jandex -->
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jandex</artifactId>
        <version>2.0.3.Final</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> 
        <version>4.11</version> <scope>test</scope> </dependency> -->

    <!-- PERSISTENCE ====================================================== -->
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-cdi -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-cdi</artifactId>
        <version>1.0.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.transaction/jta -->
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.16.1</version>
    </dependency>
</dependencies>

有什么建议吗?

0 个答案:

没有答案