1

Good day, stack.

I've been stuck on this issue for a while, there are a lot of duplicates but mine differs slightly in that my code and hierarchy looks similar to others, but refuses to work. I'll jump right in and show my code.

The app

@SpringBootApplication
public class BookstoreApplication {

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

The controller

@Controller
public class HomeController {
    @RequestMapping("/")
    public ModelAndView showHome() {
        System.out.println("Showing home page");
        return new ModelAndView("test");
    }
}

The config

@Configuration
@EnableWebMvc
@ComponentScan("com.sean.books")
public class WebConfig extends WebMvcConfigurerAdapter {
    @Bean
    public ViewResolver getViewResolver() {
        System.out.println("Settings up view resolver");
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/html/");
        resolver.setSuffix(".html");
        return resolver;
    }

    @Override
    public void configureDefaultServletHandling(
            DefaultServletHandlerConfigurer configurer) {
        System.out.println("Configuring servlet handling");
        configurer.enable();
    }
}

The html

<!doctype html>
<html lang="en" ng-app>
<head>
    <meta charset="utf-8">
    <title>Welcome to BooKart</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/app.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body>

<div id="header-wrapper">
    <span class="logo pull-left">Book cart</span>
    <span class="tagline pull-left">We have 1 million books</span>
    <div class="nav-wrapper pull-left">
        <ul class="nav nav-pills">
            <li class="active"><a href="#">Books</a></li>
            <li><a href="#">Kart</a></li>
        </ul>
    </div>
</div>

</body>
</html>

The folder structure

enter image description here

Everything seems correct, I've tried to access the css file in several different ways but I seem unable to get my css to show.

Some advice would be greatly appreciated.

7
  • I should add that if I move my html folder to my static folder, I can access the html file from my controller by removing the config and accessing the file through html/test.html, it loads properly (without css, of course). This is odd to me. Commented Feb 8, 2016 at 8:19
  • 1
    <link rel="stylesheet" href=css/app.css"> should be <link rel="stylesheet" href="css/app.css"> Commented Feb 8, 2016 at 8:24
  • @Aziz that was an editing mistake, the problem unfortunately still persists. Commented Feb 8, 2016 at 8:30
  • 1
    Is that the generated HTML you wrote? Do you get any errors in the console? can you access the CSS directly in the URL to make sure it works? What does the Network tab show you? Are you sure the /css/ folder is in the same directory as the HTML file? Commented Feb 8, 2016 at 8:31
  • 1
    can you check for the file in your root directory? localhost/www/ Commented Feb 8, 2016 at 8:34

1 Answer 1

1

The solution was to move the css folder under /WEB-INF/ to be /WEB-INF/css, for some reason having the files under static won't deploy. I'll leave it like this for now.

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

Comments

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.