相关疑难解决方法(0)

不推荐使用WebMvcConfigurerAdapter类型

我只是迁移到spring mvc版本5.0.1.RELEASE但突然在eclipse中STS WebMvcConfigurerAdapter被标记为已弃用

public class MvcConfig extends WebMvcConfigurerAdapter {
  @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
        // to serve static .html pages...
        registry.addResourceHandler("/static/**").addResourceLocations("/resources/static/");
    }
  ....
  }
Run Code Online (Sandbox Code Playgroud)

我怎么能删除这个!

java spring spring-mvc

102
推荐指数
2
解决办法
8万
查看次数

没有找到带有URI Spring MVC的HTTP请求的映射

这是我的Web.xml

dispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/servlet-context.xml 1

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

<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

我的servlet-context.xml

<context:component-scan base-package="com.springexample.controller.impl" />
    <mvc:annotation-driven />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
Run Code Online (Sandbox Code Playgroud)

最后是Handler类.它位于com.springexample.controller.impl下

@Controller
public class IndexControllerImpl implements IndexController {

    @RequestMapping("/")
    public String index() {

        return "index";
    }
}
Run Code Online (Sandbox Code Playgroud)

但是要去 localhost:8080/projectname/

它返回404错误.

Jul 27, 2013 8:18:31 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with …
Run Code Online (Sandbox Code Playgroud)

java model-view-controller spring spring-mvc

13
推荐指数
1
解决办法
11万
查看次数

如何为JSP配置spring boot mvc app?

我是Spring boot(和servlet 3.0)的新手.我试图用JSP作为视图创建spring mvc项目.当我从我的控制器返回一个视图时,它没有被解析为JstlView.

这是我做的:

@SpringBootApplication
public class MyApp extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)
@Controller
public class MainController {

    @RequestMapping( value="/main" , method = RequestMethod.GET  )
    public String main(){
        return "main";
    }

    @RequestMapping( value="/" , method = RequestMethod.GET  )
    public String welcome(){
        return "welcome";
    }
}
Run Code Online (Sandbox Code Playgroud)

src\main\webapp\WEB-INF\jsp.中创建了两个.jsp文件.

谷歌搜索后我发现我需要在application.properties中指定这个,所以我在props中添加了以下内容:


spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp


logging.level.org.springframework: TRACE
logging.level.com: TRACE
Run Code Online (Sandbox Code Playgroud)

即使在此之后它也无法正常工作.这是痕迹.

2016-04-24 19:54:49.016 TRACE 7880 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Invoking [MainController.welcome] method with arguments …
Run Code Online (Sandbox Code Playgroud)

java spring jsp spring-mvc spring-boot

7
推荐指数
2
解决办法
2万
查看次数

java springBoot - 如何呈现 html 页面

我正在使用 spring boot 尝试构建我自己的迷你网站。

我有一个控制器

package hello;


import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {


    @RequestMapping("/greeting")
    public String index() {
        return "index";
    }

}
Run Code Online (Sandbox Code Playgroud)

和我试图呈现的 html 文件资源/模板/索引,但我只是得到了文本“索引”的呈现。如何返回 html 文件而不是文本?

java web-development-server spring-boot

0
推荐指数
1
解决办法
4977
查看次数