zoukankan      html  css  js  c++  java
  • Java添加自定义注解

    今天在整合MyBatis过程中,我使用扫描的方式去扫描DAO目录下的Java文件,但是在Service层使用Autowired的时候报错,但是工程能正常运行,此处有Bug!

    解决方案:

      1.创建 annotation包

      2.定义一个注解

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    @Documented
    @Component
    public @interface MybatisMapper {
        String value() default "";
    }

      3.在spring-mybatis.xml中配置MapperScannerConfigurer

      <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.cyou.nad.goldlocker.dao.mybatis" />
            <property name="annotationClass" value="com.cyou.nad.goldlocker.annotation.MybatisMapper"/>
      </bean>

      4.在DAO层Mapper文件上添加注解

    @MybatisMapper
    public interface TopicMapper {}

      5.Service层正常使用

    @Autowired
    private TopicMapper topicMapper;
  • 相关阅读:
    二维前缀和
    素数筛法
    dp-最大连续子序列的和
    dp-最长递增子序列 (LIS)
    dp-完全背包(题)
    dp-多重背包
    dp-完全背包
    DP-01背包 (题)
    DP- 01背包问题
    DP-直线分割递推
  • 原文地址:https://www.cnblogs.com/0xcafedaddy/p/6095187.html
Copyright © 2011-2022 走看看