quarkus-arc 不满足依赖问题

2024-03-18

这是我的资源类:带有存储库注入。

@Path("/posts")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class PostsResource {


    @Context
    UriInfo uriInfo;

    @Inject
    PostRepository posts;

    @GET
    public Response getAllPosts(
        @QueryParam("q") String q,
        @QueryParam("limit") @DefaultValue("10") int limit,
        @QueryParam("offset") @DefaultValue("0") int offset
    ) {
        return Response.ok(this.posts.findByKeyword(q, limit, offset)).build();
    }

    @GET
    @Path("/count")
    public Response getAllPosts(@QueryParam("q") String q) {
        return Response.ok(
            Count.builder().count(this.posts.countByKeyword(q))
        ).build();
    }

    @POST
    public Response savePost(PostForm post) {
        Post entity = Post.builder()
            .title(post.getTitle())
            .content(post.getContent())
            .build();
        Post saved = this.posts.save(entity);
        return Response.created(uriInfo.getBaseUriBuilder().path("/posts/{slug}").build(saved.getSlug())).build();
    }

}

和存储库类

public class PostRepository extends AbstractRepository<Post, Long> {

    @Inject
    private EntityManager em;

    @Transactional
    public List<Post> findByKeyword(String keyword, long limit, long offset) {
        return this.stream()
                .filter(p -> Optional.ofNullable(keyword)
                        .map(k -> p.getTitle().contains(k) || p.getContent().contains(k)).orElse(true))
        
                .limit(limit).skip(offset).collect(toList());
    }

    @Transactional
    public long countByKeyword(String keyword) {
        return this.stream().filter(p -> Optional.ofNullable(keyword)
                .map(k -> p.getTitle().contains(k) || p.getContent().contains(k)).orElse(true)).count();
    }

    @Transactional
    public List<Post> findByCreatedBy(String username) {
        Objects.requireNonNull(username, "username can not be null");

        return this.stream().filter(p -> username.equals(p.getCreatedBy().getUsername()))
                .sorted(Post.DEFAULT_COMPARATOR).collect(toList());
    }

    @Transactional
    public Optional<Post> findBySlug(String slug) {
        Objects.requireNonNull(slug, "Slug can not be null");
        return this.stream().filter(p -> p.getSlug().equals(slug)).findFirst();
    }

    public List<Post> findAll() {
        return em.createNamedQuery("Post.findAll", Post.class).getResultList();

    }

    public Post findPostById(Long id) {

        Post post = em.find(Post.class, id);

        if (post == null) {
            throw new WebApplicationException("Post with id of " + id + " does not exist.", 404);
        }
        return post;
    }

    @Transactional
    public void updatePost(Post post) {

        Post postToUpdate = findPostById(post.getId());
        postToUpdate.setTitle(post.getTitle());
        postToUpdate.setContent(post.getContent());
    }

    @Transactional
    public void createPost(Post post) {

        em.persist(post);

    }

    @Transactional
    public void deletePost(Long postId) {

        Post p = findPostById(postId);
        em.remove(p);

    }

    @Override
    protected EntityManager entityManager() {
        return this.em;
    }

}

我的 pom.xml 包含这些依赖项:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-bom</artifactId>
            <version>${quarkus.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <!-- <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-arc</artifactId>
        <scope>provided</scope>
    </dependency> -->
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy-jsonb</artifactId>
    </dependency>
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-rest-client</artifactId>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-api</artifactId>
        <version>0.10.7</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-impl</artifactId>
        <version>0.10.7</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt-jackson</artifactId>
        <version>0.10.7</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.nimbusds</groupId>
        <artifactId>nimbus-jose-jwt</artifactId>
        <version>${nimbus-jose.version}</version>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-junit5</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
    </dependency>
<!--    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
    </dependency> -->
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-junit-jupiter</artifactId>
        <version>${mockito.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.quarkus/quarkus-jdbc-h2 -->
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-jdbc-h2</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.quarkus/quarkus-jdbc-h2 -->
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-test-h2</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-hibernate-orm-panache</artifactId>
    </dependency>
     <dependency>
     <groupId>io.quarkus</groupId>
     <artifactId>quarkus-hibernate-orm</artifactId>
   </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-security</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-smallrye-openapi</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-smallrye-metrics</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-smallrye-health</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.4</version>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-spring-web</artifactId>
    </dependency>
    <!-- <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-undertow</artifactId>
    </dependency> -->
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-spring-di</artifactId>
    </dependency>
    <!-- <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-web-client</artifactId>
    </dependency> -->
</dependencies>  

我无法构建它,因为构建返回:

Unsatisfied dependency for type com.ciwara.kalanSowApp.repository.PostRepository and qualifiers [@Default]

       - java member: com.ciwara.kalanSowApp.rest.post.PostsResource#posts

       - declared on CLASS bean [types=[com.ciwara.kalanSowApp.rest.post.PostsResource], qualifiers=[@Default, @Any], target=com.ciwara.kalanSowApp.rest.post.PostsResource]

为了要做PostRepository可注射,它必须是豆子。将类声明为 bean 最常见的方法是向该类添加 Bean-Scope 注释。

在给定的类中,添加@ApplicationScoped似乎很明智。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

quarkus-arc 不满足依赖问题 的相关文章

随机推荐

  • ggplot 和plot 如何以不同的方式处理 inf 值?

    我很难理解为什么ggplot and plot相同数据生成略有不同的图 ggplot包括顶部的 inf 值 而plot isn t with geneFDR plot log2 FC log10 FDR pch 20 main FDR vs
  • 需要使用 ASP.NET MVC 2 框架实体的帮助

    我正在使用 C 在 ASP NET MVC 2 中制作一个网站 我设计了一个数据库 其中包含一堆具有多对多关系的表 类似于以下内容 祖父母 多对多 父母 and 父级 多对多 子级 我使用实体框架来创建所有实体类 现在正在处理存储库类中的一
  • 检查 Powershell 中的范围

    我正在尝试编写一个脚本来获取计算机的 IP 地址并检查它是否属于特定的 IP 范围 例如 如果机器的 IP 是 192 168 0 5 脚本将检查它是否在 192 168 0 10 到 192 168 0 20 范围内 到目前为止 我的脚本
  • App Store开发者重命名

    我有一个个人开发者帐户 而不是公司 我发布的每个应用程序附近都写有我的名字 现在我想把它改成一个漂亮的名字 而不改变我的开发者帐户 也不注册公司 任何帮助将不胜感激 我更改了已批准的答案 因为我们被迫启动所有法律程序来获取我们公司名称的合法
  • ant:警告:无法映射用于编码 UTF8 的字符

    我见过很多像我这样的问题 但他们没有回答我的问题 因为我使用的是 ant 而不是使用 eclipse 我运行这段代码 ant clean dist它多次告诉我warning unmappable character for encoding
  • 什么是 com.android.externalstorage?

    尽管这是一个简单的问题 但我找不到答案 or 堆栈溢出 https i stack imgur com 58Zv7 png 当我使用以下代码时 我得到这个结果 com android externalstorage documents tr
  • SSIS 将一张表中的所有数据导出到多个文件中

    我有一个名为 customers 的表 其中包含大约 1 000 000 条记录 我需要将所有记录传输到 8 个不同的平面文件 这会增加文件名中的数字 例如cust01 cust02 cust03 cust04 etc 有人告诉我这可以使用
  • 如何在 Android SDK 的 eclipse 中关闭 @string 资源的警告

    我知道 从技术上讲 对字符串进行硬编码并不是最佳实践 但我可以稍后处理它 现在我只想完成我的项目的外壳 并且我对代码中的警告非常强迫 有什么方法可以关闭它吗 如果我的标题不够具体 请以此为例
  • 何时在 Ninject 中停用瞬态范围对象?

    当 Ninject 中的对象与InTransientScope 该对象不会放入缓存中 因为它是 呃 瞬态的并且没有任何范围 完成该对象后 我可以调用kernel Release obj 这会传递到缓存 在缓存中检索缓存的项目并调用Pipel
  • 如何使用 SQL::Abstract 生成 SQL 查询?

    我如何生成WHERE此查询的子句使用SQL 摘要 http search cpan org perldoc SQL 3a 3aAbstract 从表中选择 COUNT 其中 id 第111章 111 1 2 3 4 AND 状态 待处理 包
  • 获取存储在sd卡+ android中的图像的缩略图Uri/路径

    SDK版本 1 6 我正在使用以下意图打开 Android 的默认图库 Intent intent new Intent intent setType image intent setAction Intent ACTION GET CON
  • 如何使用SimpleStorage插入xml prolog来生成gpx文件?

    我计划一劳永逸地采用一个方便的工具来处理 gpx 文件的创建 我相信简单存储 http www cromis net blog downloads simplestorage 这是一个OmniXML http www omnixml com
  • 无限 while 循环和 control-c

    所以 我写了下面的代码 void main void int charNums ALPHABET i 1 char word MAX while i initialize charNums word getString word setLe
  • 一种语言的编译器如何用该语言编写? [复制]

    这个问题在这里已经有答案了 可能的重复 在 自身 中实现编译器 https stackoverflow com questions 193560 implementing a compiler in itself 引导语言 https st
  • “self”关键字在类方法中是必需的吗?

    我是 python 初学者 我了解到该方法中的第一个参数应该包含一些 self 关键字 但我发现以下程序在没有 self 关键字的情况下运行 你能解释一下吗 下面是我的代码 class Student object def init sel
  • WPF 中的 StaticResource 和 DynamicResource 有什么区别?

    在 WPF 中使用画笔 模板和样式等资源时 可以将它们指定为 StaticResources
  • 如何使用Javascript来操作模态内容?

    我正在使用 bootstrap modals 和 Ruby on Rails 我能够很好地显示模式 但在使用 Javascript 操作模式内容时遇到问题 我不确定我做错了什么 但我根本无法使用 Javascript 来影响模态的内容 以至
  • Flutter - 使用正则表达式验证电话号码

    在我的 Flutter 移动应用程序中 我尝试使用以下方法验证电话号码regex 以下是条件 电话号码必须包含 10 位数字 如果我们使用国家代码 它可以是 12 位数字 示例国家代码 12 012 数字之间不允许有空格或字符 简而言之 这
  • Rbenv 未使用正确的版本

    在我的 Rails 项目中 当我尝试运行时bundle install 我收到以下错误 Your Ruby version is 2 3 7 but your Gemfile specified 2 5 3 然而 当我跑步时ruby ver
  • quarkus-arc 不满足依赖问题

    这是我的资源类 带有存储库注入 Path posts Produces MediaType APPLICATION JSON Consumes MediaType APPLICATION JSON public class PostsRes