Tag: 春天mvc

Spring MVC错误404错误的请求Kotlin

我正在使用Kotlin开发Spring MVC应用程序。 我有一个简单的表单,当我提交时,我得到错误404错误的请求 。 我使用的Jetty服务器和Intellij社区版 。我试过调试,但因为我从来没有调试过的Web应用程序,它不是那么有用。 web.xml中 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>frontDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>frontDispatcher</servlet-name> <url-pattern>/springkotlinmvc/*</url-pattern> </servlet-mapping> </web-app> frontDispatcher-servlet.xml中 <?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: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-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:annotation-config/> <mvc:annotation-driven/> <context:component-scan base-package="org.manya.kotlin"/> <bean id="viewResolver" […]

正确的方法为不可变的构造函数注入Kotlin类

用Spring + Kotlin声明一个不可变构造函数注入类的正确方法是什么? 目前我有: @RestController public class AuthorizationController { @Inject lateinit var facebookAuth: FacebookAuthorizationService //Mutable? @RequestMapping("/authorization") public fun authorization(@RequestParam(value = "network-type", defaultValue = "Facebook") name: String, @RequestParam(value = "oauth-token") oauthToken: String, @RequestParam(value = "oauth-token-secret", required = false) oauthTokenSecret: String?): Authorization { //TODO: Handle other network types return facebookAuth.authorization(oauthToken) } } 我想facebookAuth属性是不可变的。

为springmvc使用kotlin无法实例化bean类的dataclass

我使用kotlin来ceate简单ArticlesService,我创建一个文章dataclass data class Articles(var artid: Int, var artTitle: String, var artContent: String, var artAut: String, var artTime: Date) 但类无法实例化bean类:找不到默认的构造函数; 嵌套异常是java.lang.NoSuchMethodException:com.zxl.blog.server.Articles。() @Controller class mainServer() { @Autowired val artSer: ArticlesService? = null @RequestMapping("/i") fun fuwuqi(name: String, model: ModelMap): String { model.put("name", name) return "i" } @RequestMapping(value = "/saveArt", method = arrayOf(RequestMethod.POST)) fun saveArt(art: Articles): String { return […]

使用Spring Boot和Kotlin无法提供动态Web内容

基于Spring Boot 教程来提供动态网页内容,我想在Kotlin中做同样的事情。 我的Kotlin项目是基于这个教程 。 我没有运行这两个教程的代码的问题。 从我的理解,我只需要添加一个控制器,将返回一个模板的引用。 这里HelloController.kt (位于src / main / kotlin / foo / controller下): package foo.controller import org.slf4j.LoggerFactory import org.springframework.stereotype.Controller import org.springframework.web.bind.annotation.RequestMapping @Controller class HelloController { private val log = LoggerFactory.getLogger(HelloController::class.java) @RequestMapping("/") fun hello(): String { log.info("foo") return "index" } } 以下是我想要访问的简单“模板” index.html (位于src / main / resources / templates / index.html下): […]

在@Service中使用Kotlin的Spring Boot @Autowired始终为空

目前我尝试用Kotlin重写我的Java Spring Boot应用程序。 我遇到了一个问题,即在所有使用@Service注释的类中,依赖注入都无法正常工作(所有实例均为null )。 这里是一个例子: @Service @Transactional open class UserServiceController @Autowired constructor(val dsl: DSLContext, val teamService: TeamService) { //dsl and teamService are null in all methods } 在Java中做同样的工作没有任何问题: @Service @Transactional public class UserServiceController { private DSLContext dsl; private TeamService teamService; @Autowired public UserServiceController(DSLContext dsl, TeamService teamService) { this.dsl = dsl; this.teamService = teamService; } […]