0

I work on spring boot application. I'm trying to serve static content with spring. want to serve a resource stored in the /c:/frontend/files/ directory whenever a request comes in for the URL matching the pattern: /file/**:

 @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

    registry
            .addResourceHandler("/file/**")
            .addResourceLocations("file:///C:/frontend/files/" );

}

but when i try to access to this resource using this url: http://localhost:9999/file/app.min.js

I have this problem

There was an unexpected error (type=Not Acceptable, status=406).
Could not find acceptable representation
1
  • Could you add the curl request + headers for both request and response? Commented Jan 27, 2016 at 14:03

2 Answers 2

2

I resolved the problem. it's related to "spring-cloud-config-server". I just delete this config: org.springframework.cloud spring-cloud-config-server

Sign up to request clarification or add additional context in comments.

Comments

1

It sounds like your project's folder structure is wrong.

Code should go under src/main/java and resources (like your javascript) should go under src/main/resources. You have a few different options where you can actually serve the files from. This post on the spring.io blog has the following to say:

Spring Boot will automatically add static web resources located within any of the following directories:

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

Another option you also have is using webjars.

Personally, I've found it easiest to put those kind of files under src/main/resources/public. It always works without any issues for me. The interesting thing is you can put a folder named /public anywhere in your project and spring-boot will serve files out of it. You have to be really careful that it's under src/main/resources/public though if you're using a build tool like maven, as when you come to build your .jar the files won't be in the right place otherwise.

1 Comment

Yes, folders with static content should be under class path or directory deploying web app. So one way is to put the static folder under src/main/resource, then Maven will help build it into class path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.