Reputation: 45
I am a newbie to Spring Boot. In the following simple code when I am using @RequestMapping, http://localhost:8080/person results in the following error:
Error:
There was an unexpected error (type=Not Found, status=404).
Code:
@Configuration
@EnableAutoConfiguration
@ComponentScan
@Controller
public class SpringBootAlphaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAlphaApplication.class, args);
}
@RequestMapping("/person")
public String addPerson(Model model){
Person person = new Person();
person.setName("SomeName");
person.setAge(28);
model.addAttribute("person", person);
return "personview";
}
@RequestMapping("/")
public String testPath(){
return "Test URL";
}
}
Upvotes: 0
Views: 732
Reputation: 44745
Considering your answer, then you should actually have gotten another error. If you're using spring-boot-starter-thymeleaf, the error you would get if your view can be resolved (but does not contain a </meta>
tag), should be:
org.xml.sax.SAXParseException: The element type "meta" must be terminated by the matching end-tag "</meta>".
And you should get a type=Internal Server Error, status=500
status.
To solve that you can actually configure the strictness of Thymeleaf by setting its mode to LEGACYHTML
:
spring.thymeleaf.mode=LEGACYHTML5
However, it requires you to add another dependency called nekohtml:
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.15</version>
</dependency>
The not found error usually means something else:
Upvotes: 1
Reputation: 45
It was caused by <meta>
not having an ending tag </meta>
. Apparently Thymleaf is very strict with tags, wish more meaningful messages were returned instead of a 404 Not Found.
Upvotes: 0