相关疑难解决方法(0)

如何在tomcat服务器上部署spring boot Web应用程序

我已经创建了spring boot web应用程序,但我无法在tomcat上部署spring boot web应用程序WAR文件,我可以将其作为java应用程序运行.如何在tomcat上将spring boot应用程序作为Web服务运行.我正在使用以下代码.如果可以在tomcat上运行,请在不使用web.xml和使用web.xml的情况下帮助我使用注释.

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
       return application.sources(Application.class);
    }

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

}
Run Code Online (Sandbox Code Playgroud)

以下代码为休息控制器

@RestController
public class HelloWorld{

   @RequestMapping(value = "/hello", method = RequestMethod.GET)
   public ResponseEntity<String> get() {
       return new ResponseEntity<String>("Hello World", HttpStatus.OK);
   }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Pom.xml

<groupId>org.springframework</groupId>
<artifactId>web-service</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.0.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
    </dependency>
        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java spring tomcat spring-mvc maven

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

Spring MVC:错误400客户端发送的请求在语法上是不正确的

这似乎是一个常见问题.我已经完成了SO中给出的所有答案,但无法使其发挥作用.
我正在尝试将Spring MVC + Freemarker集成到现有的Web应用程序中.它适用于GET请求,Freemarker Template读取Controller提供的java对象,没有任何问题.
但表单提交无法触及Controller方法.最后我让log4j工作了.这是我得到的错误:
错误

    HandlerMethod details: 
    Controller [application.entry.controller.UserController]
    Method [public void application.entry.controller.UserController.handleSave(java.lang.String)]

    org.springframework.web.bind.MissingServletRequestParameterException: 
Required String parameter 'action' is not present
Run Code Online (Sandbox Code Playgroud)


Freemarker的:

<form method="POST" action="save.html">
  ------------
  <input type="submit" class="btnnew" name="saveWithoutValidation" value="Save Without Validation"></input>
  <input type="submit" class="btnnew" name="submit" value="Submit"></input>
</form>
Run Code Online (Sandbox Code Playgroud)

context-root是PORTAL.
为spring-servlet.xml

<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
      <property name="cache" value="true"/>
      <property name="prefix" value=""/>
      <property name="suffix" value=".ftl"/>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

调节器

@RequestMapping(value="/save", method=RequestMethod.POST)
    public void handleSave(@RequestParam …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

9
推荐指数
3
解决办法
11万
查看次数

标签 统计

java ×2

spring ×2

spring-mvc ×2

maven ×1

tomcat ×1