MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    插件使用Spring容器,放入console后启动找不到bean

    开发交流
    2
    11
    220
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      oneoness last edited by

      70356fb7-5eaf-4c50-9252-14abaed38380-image.png

      9a90b975-4b5c-45a1-bf5f-1863a7c9d5f5-image.png

      在插件中用psvm测试是可以获取到bean的,但是不知道为什么打包放入console之后就不行了

      1 Reply Last reply Reply Quote 0
      • O
        oneoness last edited by

        这是启动类

        image.png

        1 Reply Last reply Reply Quote 0
        • cssxsh
          cssxsh last edited by

          有什么必要引用 spring 吗
          spring 的 本身就是一个 框架等级 库,一般用来写独立应用的

          你塞到插件就是 在拿汽车牵引火车

          O 1 Reply Last reply Reply Quote 0
          • O
            oneoness @cssxsh last edited by

            @cssxsh 想用Spring的RestTemplate

            cssxsh 1 Reply Last reply Reply Quote 0
            • cssxsh
              cssxsh @oneoness last edited by

              @oneoness
              你想搞 客户端还是服务端?

              O 2 Replies Last reply Reply Quote 0
              • O
                oneoness @cssxsh last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • O
                  oneoness @cssxsh last edited by

                  @cssxsh 服务端,想去调一些网站的api

                  cssxsh 1 Reply Last reply Reply Quote 0
                  • cssxsh
                    cssxsh @oneoness last edited by

                    @oneoness

                    你这是 客户端吧,我觉得你可以直接使用 Okhttp 或者 ktor
                    之类的客户端
                    没必要套一层 spring,成本太高了

                    O 1 Reply Last reply Reply Quote 0
                    • O
                      oneoness @cssxsh last edited by

                      @cssxsh 确实,我现在正在考虑换成JDK11自带的HttpClient。不过还是没明白为什么Spring的Bean出问题了

                      cssxsh 1 Reply Last reply Reply Quote 0
                      • cssxsh
                        cssxsh @oneoness last edited by

                        @oneoness

                        spring 注解自动配置是基于类扫描的
                        mirai-console 插件加载 和 正常的单个JAR 直接运行 spring 的情况不一样,需要改很多默认配置

                        O 1 Reply Last reply Reply Quote 1
                        • O
                          oneoness @cssxsh last edited by

                          @cssxsh 原来是这样,感谢解惑

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact