【问题标题】:Spring don't see controller春天看不到控制器
【发布时间】:2015-12-06 15:30:31
【问题描述】:

我的 Spring MVC 应用程序有问题。当我尝试在弹簧控制器和角度控制器之间传递数据时,我的应用看不到我的控制器。

弹簧配置:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://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"
version="3.0">
<display-name>PiManager</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

调度程序-servlet.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:jpa="http://www.springframework.org/schema/data/jpa"
 xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/data/jpa 
                    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context-4.0.xsd
                    http://www.springframework.org/schema/jdbc 
                    http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
                    http://www.springframework.org/schema/mvc 
                    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">
<mvc:annotation-driven />
<context:component-scan base-package="org.inz.controller" />

<jpa:repositories base-package="org.inz.repositories"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/" />
  <property name="suffix" value=".jsp" />
</bean>

我的 services.js

PiManager.services.main = [ '$http', '$rootScope', '$state', function($http, $rootScope, $state) {
var self = this;

self.getTestEntity = function(id) {
    return $http.get("/PiManager/index/"+id);
}
} ];

app.service('mainService', PiManager.services.main);

我的控制器.js

"use strict"

PiManager.controllers = {};

PiManager.controllers.main =
['mainService', '$scope', '$state', '$http', function(mainService, $scope, $state, $http) {

$scope.getTest = function(id) {
    mainService.getTestEntity(id).then(function(response) {
        $scope.testEntityPart = response;
    });
}

}];
 app.controller('mainController', PiManager.controllers.main);

我的春天主控制器

@Controller
@RequestMapping("/PiManager/")
public class MainController {

@Autowired
private TestEntityRepository testEntityRepository;

@RequestMapping(value = "/main")
public String index() {
    return "/index.jsp";
}

@ResponseBody
@RequestMapping(value = "/index/{id}", method = RequestMethod.GET)
public List<TestEntity> getTestEntity(@PathVariable("id") Long id) {
    return testEntityRepository.findById(id);
}
}

所以当我输入http://localhost:8080/PiManager/index/1 我得到了

GET http://localhost:8080/PiManager/index/1 404 (Not Found)

我真的不知道该怎么做才能让它发挥作用。

【问题讨论】:

标签: java angularjs spring spring-mvc


【解决方案1】:
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

【讨论】:

  • 还是什么都没有。现在我得到了 WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/PiManager/main] in DispatcherServlet with name 'dispatcher'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-15
  • 1970-01-01
  • 2019-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多