Reputation: 178
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
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.
Upvotes: 1
Views: 171
Reputation: 178
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.
Upvotes: 1