Why is Spring @Value incompatible with @Controller?

前端 未结 4 1986
执念已碎
执念已碎 2021-01-13 13:00

I\'m looking for a better understanding of this problem. A workaround is pretty simple, namely move the configuration data to another class that does not have proxies/advic

4条回答
  •  我在风中等你
    2021-01-13 13:31

    First of, the notation using the $ is correct, not the #

    Now regarding the original poster, I think you have a conflicting behavior between the 2 annotations (@Controller and @Transactional).

    Using the @Transactional annotation will proxify your implementation (I guess to detect an error and launch a rollback).

    Now you are saying that you see 2 instances of your controller. That should not happen. Normally you should have only a single instance of a controller loaded in memory.

    Could be related to your configuration files or due to the presence of @Transactional and its proxy nature?

    As a side note, I never use @Transactional in the controllers themselves but either on a method of a service or dao. Since the actual process which can fail and need to be rollbacked is there, and can be access from different controllers/source.

    Regards.

提交回复
热议问题