Series I bond with 404 (a) recording a retarded generic error

Since learning springboot and springcloud, have not reuse ssm.

Today, I decided to dust off ssm set up, so did a small project, only the simple data query capabilities, never thought actually gave me a reported 404.

 

First on the code: The following code annotations, in part, I understand, may be wrong!

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
    
    <context:component-scan base-package="com.learn.ssm">
    <!-- context:component-scan paths for scanning the file, the class file if the scanning with @ Service, @ Component, @ Repository , @ Controller like these annotations, put these classes registered as the bean 
      -> 
        
    </ context: Component-scan > 
        
    <the bean ID = "the dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource"> 
        <Property name = "URL" value = "JDBC: MySQL: //127.0.0.1: 3306 / yxktv" /> 
        <Property = name "driverClassName" value = "com.mysql.jdbc.Driver" /> 
        <Property name = "username" value = "the root" /> 
        <Property name = "password" value = "X5" /> 
    </ the bean> 
    
    <the bean ID = "SqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.learn.ssm.mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
</beans>

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/mvc   http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd ">
 
    <MVC: Annotation-Driven /> 

    <- static allocation of resources ->! 
    <MVC: Resources Mapping =" / static / ** "LOCATION =" / static / "/> 

    <-! view resolver -> 
    <the bean ID =" the viewResolver " class =" org.springframework.web.servlet.view.InternalResourceViewResolver "> 
        <Property name = "prefix" value = "/" /> 
        <Property name = "suffix" value =. "JSP"> </ Property> 
    </ the bean> 
    <- annotations using packet, the subset comprising ->! 
    <context: component- Scan 
        Base - Package Penalty for = "COM.learn.ssm.controller" />
</beans>
        


web.xml

<? xml Version = "1.0" encoding = "UTF-8"?> 
<Web-App xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "HTTP: // the Java .sun.com / xml / ns / javaee " xsi: schemaLocation =" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0 .xsd "ID =" WebApp_ID "Version =" 3.0 "> 
  <the display-name> SSM </ the display-name> 
  <context-param> <-! initialization context parameter -> 
    <param-name> the contextConfigLocation </ param -name> 
    <param-value> CLASSPATH: the applicationContext.xml </ param-value> 
  </ context-param> 
  ! <listener> <- listener listens for a variety of operations, some operations may be triggered automatically -> 
    <listener - class > org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <the servlet-name> SPRINGMVC </ the servlet-name> 
    <servlet- class > org.springframework.web.servlet.DispatcherServlet </ servlet- class > 
    <the init-param> 
      <param-name> the contextConfigLocation </ param-name> 
      < value-param> CLASSPATH: springmvc.xml </ param-value> 
    </ the init-param> 
    <Load-ON-Startup>. 1 </ Load-ON-Startup> 
    ! <- Load-ON- Startup when the value is 0 or when greater than 0, represents the container when the application starts to loading the servlet; 
when a negative number is or is not specified, indicates that a container loaded when the servlet is selected. 
The smaller the value of a positive number, the higher priority start the servlet. 
     -> 
  </ the servlet> 
  <-Mapping the servlet> 
    <the servlet-name> SPRINGMVC </ the servlet-name> 
    <If the url-pattern is defined by a path, then the servlet handling all requests for resources after this path defined by the servlet-name. 
            If the url-pattern is defined by, for example, resource format * .do the like, then for all meet these the formats of the requested resource specified by the servlet process.
     -> 
  </ Mapping the servlet-> 
  <File-List-available for purchase> 
    <File-available for purchase> index.html </ File-available for purchase> 
  </ File-List-available for purchase> 
</ Web-App>

SsmController.java

package com.learn.ssm.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.learn.ssm.pojo.stu;
import com.learn.ssm.service.SsmService;
@RestController
@CrossOrigin
public class SsmController {
 @Autowired
 SsmService ssmService;
 @GetMapping("/show")
 public List<stu> show(){
  return ssmService.show();
 }
}

SsmMapper.xml

package com.learn.ssm.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.learn.ssm.pojo.stu;
@Mapper
public interface SsmMapper {
 @Select("select * from stu")
 public List<stu> show();
}

SsmService.xml

package com.learn.ssm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.learn.ssm.mapper.SsmMapper;
import com.learn.ssm.pojo.stu;

@Service
public class SsmService {
    @Autowired
    SsmMapper ssmMapper;
    public List<stu> show(){
        return ssmMapper.show();
    }
}

stu.java

package com.learn.ssm.pojo;

public class stu {
    
    String name;
    String sex;
    int id;
    int age;
    int date;
    int classs;
    int tall;
    int num;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getDate() {
        return date;
    }
    public void setDate(int date) {
        this.date = date;
    }
    public int getClasss() {
        return classs;
    }
    public void setClasss(int classs) {
        this.classs = classs;
    }
    public int getTall() {
        return tall;
    }
    public void setTall(int tall) {
        this.tall = tall;
    }
    public int getNum() {
        return num; 
    } 
    Public  void setnis ( int num) {
         this .num = num; 
    } 
    
}

 

 When I enter the browser to http: // localhost: When 8080 / show.do, reported that 404, because my address was wrong, it should be http: // localhost: 8080 / ssm20190627 / show.do.

By their own stupid to cry ... ...

And then add that personal understanding:

After the start tomcat, 8080 Port tomcat will be occupied, however, is in tomcat can deploy multiple projects at the same time, if you visit http: // localhost: 8080 / show.do, then visit a project which is it? So, we need to add the project name, to distinguish, http: // localhost: 8080 / ssm20190627 / show.do.

Guess you like

Origin www.cnblogs.com/wxdmw/p/11099558.html