Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在名为';弹簧&x27;_Java_Spring_Spring Mvc - Fatal编程技术网

Java 在名为';弹簧&x27;

Java 在名为';弹簧&x27;,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在一个教程网站上尝试一个简单的Spring注释示例,但是当我用指定的URI点击URL时,我得到了这个错误,在网上搜索发现了许多解决方案,但没有一个有效 下面是代码片段: Web.xml <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServle

我正在一个教程网站上尝试一个简单的Spring注释示例,但是当我用指定的URI点击URL时,我得到了这个错误,在网上搜索发现了许多解决方案,但没有一个有效

  • 下面是代码片段:
Web.xml

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>  
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

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

    <listener>
        <listener-class>
                      org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <?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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.spring.annotation" />

        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>
现在当我在浏览器中运行这个程序时

http://localhost:8080/SpringAnnotation/hello
我没有收到任何错误,只有简单的警告,我被卡住了:

Jan 19, 2015 3:10:06 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringAnnotation/hello] in DispatcherServlet with name 'spring'
我在spring-servlet.xml中没有看到
。 你试着添加这个吗?
此标记用于在扫描的包和注释@Controller之间建立链接。您在
spring context.xml中缺少MVC配置。应该是这样的

<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.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-3.0.xsd">

    <context:component-scan base-package="com.spring.annotation" />

    <mvc:annotation-driven />

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

</beans>

您缺少
mvc
名称空间声明,加上
,以让Spring知道您正在使用注释进行配置。

您指定了@RequestMapping错误的方法请尝试这种方法
You have specified @RequestMapping wrong way try this way 
@RequestMapping(value = "/home", method = RequestMethod.GET)

Also its may be due to wrong url ,may be your application name is wrong 
To know your application name go to pom.xml and see this entry :

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.test</groupId>
        <artifactId>SpringTest</artifactId>
        <name>SpringAnnotation</name>
        <packaging>war</packaging>

  name of application in this case is SpringTest and related url is /SpringTest/home. Use same thing in your project.
@RequestMapping(value=“/home”,method=RequestMethod.GET) 也可能是由于错误的url,可能是您的应用程序名称错误 要了解应用程序名称,请访问pom.xml并查看以下条目: 4.0.0 com.test 弹簧试验 SpringAnnotation 战争 本例中的应用程序名称为SpringTest,相关url为/SpringTest/home。在项目中使用相同的东西。
将Maven项目更改为普通的动态Web项目

一切都是一样的,甚至被移除了
来自spring-servlet.xml的标记。现在工作得很好


现在我的问题是,,pom.xml是否是警告出现的根本原因?

在url模式中使用
/*
,然后再次尝试停止工作sameYes我已经尝试过了,仍然是相同的警告是的,我已经添加了,但是仍然是相同的警告如果您也添加了
?现在添加了控制台上的警告,但是仍然是web浏览器在您试图访问
SpringAnnotation
的问题中显示HTTP状态404-/springmavennotation/hello,而不是
springmavennotation
?不管怎么说,是否调用了控制器方法?如果调用它,您也会得到404,但是在配置的位置找不到
default.jsp
。是的,很抱歉,jsp位于它的完美位置,如果它一直运行到控制器,它必须将语句打印到其中,但我认为xml无法重定向到完美的控制器
You have specified @RequestMapping wrong way try this way 
@RequestMapping(value = "/home", method = RequestMethod.GET)

Also its may be due to wrong url ,may be your application name is wrong 
To know your application name go to pom.xml and see this entry :

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.test</groupId>
        <artifactId>SpringTest</artifactId>
        <name>SpringAnnotation</name>
        <packaging>war</packaging>

  name of application in this case is SpringTest and related url is /SpringTest/home. Use same thing in your project.