MrSolid51 MrSolid51 - 1 month ago 10
Java Question

is there a reason for RequestMappingHandlerMapping not mapping in here?

I'm a student in learning, java spring frame in particular(for now).

I'm doing a review(along with the exercise given) on the stuff I've learned using mybatis.
I'm having a pretty hard time catching up on this(teacher, too darn fast)

what i'm trying to make is to get a page with a simple chart that would get list of employees in the company in chart.

but when i try to run and click on a link(which goes to do the real work) it i get this:

WARN PageNotFound - No mapping found for HTTP request with URI [/spring_mvc13_batisTest/list] in DispatcherServlet with name 'dispatcherServlet'

error message with 404 error on page.

this is my pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.samples.service.service
spring_mvc13_batisTest
0.0.1-SNAPSHOT
war

<properties>

<!-- Generic properties -->
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Web -->
<jsp.version>2.2</jsp.version>
<jstl.version>1.2</jstl.version>
<servlet.version>2.5</servlet.version>


<!-- Spring -->
<spring-framework.version>4.1.3.RELEASE</spring-framework.version>

<!-- Hibernate / JPA -->
<hibernate.version>4.2.1.Final</hibernate.version>

<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>

<!-- Test -->
<junit.version>4.11</junit.version>

</properties>

<dependencies>

<!-- Spring MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<!-- Other Web dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>

<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>


<!-- Test Artifacts -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- mariadb jdbc -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>

<!-- //10.7-2-0 added -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>



<!-- MYBATIS -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>


</dependencies>




my mvc-config.xml

<context:component-scan base-package="pack.controller"/>

<mvc:annotation-driven />


<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>


and java file which supposed to read from:

package pack.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import pack.model.SawonDto;
import pack.model.SawonInter;
@Component
@ComponentScan("pack.model")
public class ListController {

@Autowired
private SawonInter inter;

@RequestMapping(value="list", method= RequestMethod.GET)
public Model processSelect(Model model){
model.addAttribute("lists", inter.selectList());
return model;

}
}


Github link on my work
folder ending with batisTest is what i'm doing, and other one is one I've wrote during class while being taught. ive been holding this for a full day and no luck at all :(

anyone kind enough to explain? I tried to search here and there but I just dont get it...

Answer

Because your ListController class is not Spring MVC controller yet. You need to add spring @Controller annotation in your controller.

eg.

import org.springframework.stereotype.Controller;

@Component
@ComponentScan("pack.model")
@Controller
public class ListController {

Also I would recommend great Spring MVC website for your references.Hope its help.

https://www.mkyong.com/tutorials/spring-mvc-tutorials/

Comments