Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

Swoft中使用Inject ,with @xxx must be define class annotation

  • Demo继承一个父类,然后父类中使用inject注入一个bean,这个时候会报错,
  • with @xxx must be define class annotation
  • 提示的错误信息是,使用属性注解必须有类注解,,问题是父类中应该不需要有类注解的么?不懂求解
  • 父类中怎么处理,不懂!!

DemoCommand

<?php declare(strict_types=1);

namespace AppConsoleCommand;

use SwoftConsoleAnnotationMappingCommand;
use SwoftConsoleAnnotationMappingCommandMapping;

/**
 * @Command()
 */
class DemoCommand extends CommCommand
{
    /**
     * @CommandMapping()
     */
    public function test(): void
    {
        $this->tests();
        var_dump("test_demo");
    }
}

CommCommand

<?php declare(strict_types=1);
namespace AppConsoleCommand;

use AppServiceDemoService;
use SwoftBeanAnnotationMappingInject;

class CommCommand
{
    /**
     * @Inject()
     * @var DemoService
     */
    private $d;
    public function tests() {
        $this->d->demo();
        var_dump("tests");
    }
}

DemoService

<?php declare(strict_types=1);
namespace AppService;

use SwoftBeanAnnotationMappingBean;

/**
 * @package AppService
 * @Bean(name="demoservice", scope=Bean::PROTOTYPE)
 */
class DemoService {
    public function demo() {
        var_dump("demo");
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...