I'm developing a Symfony 3 application. Symfony profiler log tells me:
依赖于服务自动注册类型"AppEntitySubDirCategory"已自3.4版本起被弃用,并且在4.0版本中将不再支持。 请创建一个名为"AppEntitySubDirCategory"的服务。
However, this is just a simple ORM bean:
/** * @ORMEntity * @ORMTable(name="category") */ class Category { ...
How should I solve this problem? Do I really need to declare the ORM entity as a service in services.yaml
? If yes, what should be done?
UPDATE In fact, my entities are in a subdirectory. I've modified my question.
In my service.yaml
I tried:
App: resource: '../src/*' exclude: '../src/{Entity,Repository,Tests,Entity/SubDir}'
...But it has no effect.
Do you have a class under Service-auto registration that uses entities as constructor parameters?
This is where your problem lies.
You need to ask yourself whether this related class is really a service, or just an ordinary object that you always create instances yourself.
If it is not used as a service through a container, you have two options:
You can exclude this class through a global pattern similar to the following:
Or you can set the following parameters in your configuration:
With this option, the container will not try to create a service class with parameters that are not available as a service, and you will get a decisive error. This is the default setting for sf4.
A good example that triggers this error is a custom event class that takes an entity as a payload in the constructor:
Now, if this file is not specifically excluded, the container will attempt to automatically register it as a service. Since the solid body is excluded, it cannot be autowired. But in 3.4, there is this fallback mechanism that triggers this warning. Once strict_mode is activated, the event is not available as a service and will throw an error if you try to use it as a service.