简体   繁体   中英

How to force spring-boot to refresh resources?

I would like to control a camera using a web app. The client have to ask to the server for a preview immage. I'm saving the preview immage in :

src

└── main

    └── resources

         └── public

             └── img

When i try to get a new preview i get the old picture (but the new one have alredy overrided that), after refreshing the resource folder manually from the IDE, i get the right-one. Am I putting in the wrong folder the image? There is some way to make this refresh automatic ?

You can control in which directories Spring Boot is going to look for static resources. You are updating the sources of your project so there's no way Spring Boot is going to look there by default: when you run an app, the only thing the process can "see" is the classpath.

You can teach Spring Boot to look elsewhere. Let's assume for the sake of this example that you want to save your resources in /Users/foo/data , add the following to your configuration:

spring.resources.static-locations=classpath:/static/,file:/Users/foo/data

If you're saving a foo.png in /users/foo/data then it will be available at the root of your app (ie http://localhost:8080/foo.png ). If the resources can be located at several locations, make sure to put the directory with the most recent image first in the list above.

感谢所有您的答复,我通过读取新的immage文件中的ResponseEntity <byte[]>并使用ResponseEntity <byte[]>返回它们来解决了问题。

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