So, today I finally decided to try out IntelliJ IDEA.
After setting up everything I tried to make a VERY simple Spring webMVC Project.
And as this is a Spring application, I'm at a point where I don't have any errors or warnings but just 404 page when I run my project...
Tomcat 9 runs without any warnings or errors and Java seem also to have no problems. Running will open a browser with the way way too common 404 - resource not found error.
SpringTest.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.clomez</groupId>
<artifactId>SpringTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
HomeController
package com.clomez.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Created by Clomez-admin on 14.4.2017.
*/
@Controller
public class HomeController {
@RequestMapping(value = "/")
public String home(){
return "home";
}
}
WebInit.class
package com.clomez.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
/**
* Created by Clomez-admin on 14.4.2017.
*/
@Configuration
public class WebInit extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{RootConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{WebConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
RootConf.class
package com.clomez.config;
import org.springframework.context.annotation.Configuration;
/**
* Created by Clomez-admin on 14.4.2017.
*/
@Configuration
public class RootConfig {
}
WebConfig.class
package com.clomez.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
/**
* Created by Clomez-admin on 14.4.2017.
*/
@Configuration
@EnableWebMvc
@ComponentScan("com.clomez")
public class WebConfig extends WebMvcConfigurerAdapter{
@Bean
public InternalResourceViewResolver resolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/");
resolver.setSuffix(".jsp");
return resolver;
}
}
Please can anybody help me with this? After two months I mostly feel like getting a cancer from this Spring framework thing, but I don't have choice if I want to complete my degree.
Tomcat runs smoothly, there aren't any errors or warnings in the editor, and it brings up a browser with 404 - home.jsp not found.