简体   繁体   中英

Spring Boot Index wrong routing

I'm currently using an index.html in my public folder. It was displaying correctly, then somewhere along development, the routing broke and now

http://localhost:8080/ shows:

{
  "_links" : {
    "users" : {
      "href" : "http://localhost:8080/users"
    },
    "profile" : {
      "href" : "http://localhost:8080/alps"
    }
  }
}

instead of my index.html. Strangely enough the users link returns a json list of my users table.

How do I revert back to my index.html page?

Application.java

package com.exp;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableAutoConfiguration(exclude = { JacksonAutoConfiguration.class })
@EnableAsync
@EnableScheduling
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}

Obviously you have added Spring Data REST as dependency, which produces this output. However, it should only show this, if you use the Accept header with application/json in your request which shouldn't be the case for a regular browser.

One solution would be to remove this dependency.

The other solution would be, that you change the base path for Spring Data REST, so you can distinguish it from the other resources in your application. For that, add the following property to your application.properties :

spring.data.rest.base-uri=/yourbasepath

I had an empty folder src/main/webapp that was being picked up before public/. Could have possibly been created when I changed my spring boot packaging from jar to war.

deleting the webapp folder, or shifting files from public to webapp solves the issue.

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