Java Spring mvc异常中的空servlet名称

Java Spring mvc异常中的空servlet名称,java,spring,spring-mvc,freemarker,servletexception,Java,Spring,Spring Mvc,Freemarker,Servletexception,我在spring mvc中遇到了下一个问题 以下是我想测试的控制器中的方法: @Controller @RequestMapping("/groups") public class GroupController { @Autowired private GroupService groupService; @RequestMapping(method = RequestMethod.GET) public String getGroups() {

我在spring mvc中遇到了下一个问题

以下是我想测试的控制器中的方法:

    @Controller
@RequestMapping("/groups")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @RequestMapping(method = RequestMethod.GET)
      public String getGroups() {
        return "groups";
    }
Spring配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   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/context http://www.springframework.org/schema/context/spring-context.xsd
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="com.softserveinc.ita"/>
<mvc:annotation-driven />
<mvc:resources location="/WEB-INF/css/" mapping="css/**"/>
<mvc:resources location="/WEB-INF/js/" mapping="js/**"/>
<mvc:resources location="/WEB-INF/images/" mapping="images/**"/>
<mvc:resources location="/WEB-INF/template/" mapping="template/**"/>

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="suffix" value=".ftl"/>
</bean>
<bean id="jsonUtil" class="com.softserveinc.ita.utils.impl.JsonUtilGsonImpl"/>
我在控制器中有更多的方法和更多的测试,但只有1个不起作用。我有以下例外:

javax.servlet.ServletException:无法解析名为“”的servlet中名为“”组“”的视图

为什么servlet名称为空?当我运行应用程序时,cotroller中的getGroups方法工作正常,但未通过测试

当我将视图解析器从ftl更改为jsp时

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

它与这个视图解析器完美配合。

我看不出您是如何加载spring配置文件的。请使用web.xml加载spring配置文件,这可能会解决您的问题

<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>your spring config file location</param-value>
</init-param>    
<load-on-startup>1</load-on-startup>
</servlet>

我通过Intellij idea中的facets加载配置文件。我试着像你一样更改我的web.xml,但没有成功
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>your spring config file location</param-value>
</init-param>    
<load-on-startup>1</load-on-startup>
</servlet>