这几天我正在学习 Java Spring。我正在做一个关于 Spring 和 Rest Api 的简单示例。我想将“Hello World”写入浏览器。我使用了 @restController 。我可以为我的示例找到任何解决方案。
我的Java代码
package webgroup.webartifact;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping(value="/getHelloWorld")
@ResponseBody
public String getHelloWorld() {
return "Hello World ";
}
}
我的 xml 文件是
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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.xsd">
<context:component-scan base-package="webgroup.webartifact"/>
<context:annotation-config />
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix">
<value>/WEB-INF/</value>
</property>
<property name= "suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
当我运行这个项目时,给我一个 http 状态 500 错误。我搜索错误,但我没有解决方案。
尚方宝剑之说
慕虎7371278
相关分类