简体   繁体   中英

How to get Spring MVC Controller to load lazily?

I am not able to get Spring MVC Controllers to lazy load.

I have tried the solution mentioned in Does Spring MVC initialize all controllers on start up??

Here is my code:

app-servlet.xml

<context:component-scan base-package="com.mvc.controller">

AssetController.java

@Lazy(value=true)
@Controller
@RequestMapping("/api/asset")
public class AssetController{


  @Autowired
  private AssetService assetService;

What am I missing here?

Spring v3.0.7

@RequestMapping annotation makes controller to be initialized eagerly despite the fact that it is also annotated with @Lazy(value=true) .

In your case, removing @RequestMapping annotation should make the controller initialize lazily. Though I do not know if it is possible to use @RequestMapping annotation and have that controller load lazily, I did not manage to achieve it (solved my issue without making the controller load lazily, but that is out of scope of this question).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM