小编nod*_*e42的帖子

除非@RequestParam"required = false",否则Spring不接受POST参数

我正在运行Spring 3.1.2应用程序.我有一个RESTful servlet,有许多方法.GET方法工作得非常好(@PathVariables匹配,响应正确地编组为基于Accept标头的JSON或XML等)100%的时间.

但是POST方法根本不起作用.经过几个小时的捣乱与皈依者以及我能找到的所有其他春天方面(所有修修补补),我把它缩小到required现场@RequestParam.这是我用来调查的简化测试方法:

@RequestMapping (value = "/bogus",
                 method = POST)
public @ResponseBody PassResponse bogus (
            @RequestParam (value = "test", required = false) String test) {
    // Just some handy garbage objects that marshal to JSON/XML
    UserResponse user = new UserResponse ();
    user.setName (test);
    AccountDetail detail = new AccountDetail (user,null);
    return new PassResponse (detail);
}
Run Code Online (Sandbox Code Playgroud)

required = false:一切正常(参数被接收和解释).正如我所期望的那样

required = true :(或未指定,因为这是默认值)我一直收到消息" MissingServletRequestParameterException:Required String parameter'test'不存在 "

客户端视图:

需要= TRUE

Request URL:http://localhost:8080/internal-project/rest/bogus
Request Method:POST …
Run Code Online (Sandbox Code Playgroud)

rest spring

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

PropertySourcesPlaceholderConfigurer未在SpringBoot项目中向Environment注册

我正在将一个工作项目从使用SpringBoot命令行参数移动到从文件中读取属性.以下是该@Configuration课程的相关部分:

@Configuration
class RemoteCommunication {

    @Inject
    StandardServletEnvironment env


    @Bean
    static PropertySourcesPlaceholderConfigurer placeholderConfigurer () {
        // VERIFIED this is executing...
        PropertySourcesPlaceholderConfigurer target = new PropertySourcesPlaceholderConfigurer()
        // VERIFIED this files exists, is readable, is a valid properties file
        target.setLocation (new FileSystemResource ('/Users/me/Desktop/mess.properties'))
        // A Debugger does NOT show this property source in the inject Environment
        target
    }


    @Bean  // There are many of these for different services, only one shown here.
    MedicalSorIdService medicalSorIdService () {
        serviceInstantiator (MedicalSorIdService_EpicSoap, 'uri.sor.id.lookup.internal')
    }


    // …
Run Code Online (Sandbox Code Playgroud)

groovy spring spring-boot

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

Spring-Boot无法在WAR文件中查找JSP页面

运行spring-boot项目(java -jar /path/to/war.war)时,找不到.jsp文件.

使用@ResponseBody注释的方法可以正常工作.视图解析器提供了JSP页面的正确路径,但找不到它们.该项目有一个配置类,没有web.xml.

配置类:

@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@ComponentScan (basePackages = "org.ghc.security.web")
class ScMain extends WebMvcConfigurerAdapter {


    // SpringBoot BootStrap...
    static void main (String[] args) {
        ApplicationContext ctx = SpringApplication.run (ScMain, args)

        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        beanNames.each { beanName ->
            System.out.println(beanName);
        }
    }


    @Bean
    InternalResourceViewResolver internalResourceViewResolver () {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver()
        viewResolver.setPrefix("/WEB-INF/jsp/")
        viewResolver.setSuffix(".jsp")
        viewResolver
    }
}
Run Code Online (Sandbox Code Playgroud)

调节器

@Controller
class Running {

    @RequestMapping ("/alive")  // This works fine
    @ResponseBody
    String …
Run Code Online (Sandbox Code Playgroud)

java groovy spring spring-mvc spring-boot

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

如何删除Orphan Kubernetes Pods

我正在通过Docker运行Kubernetes .在本教程之后,我使用了Nginx POD kubectl run nginx --image=nginx --port=80.然而,这似乎创建了孤立的POD(没有复制控制器).kubectl get rc没有返回任何内容并kubectl describe pod nginx-198147104-kqudh显示复制控制器:none(kubectl版本"v1.2.0 + 5cb86ee"显示控制器:ReplicaSet/nginx-198147104但将其缩放为0只会导致创建一个新的Nginx pod,它不能删除).

我希望能够从Docker中删除Kubernetes托管的Nginx容器.我没有太多运气找出如何删除一个孤儿吊舱(没有重新创建......).

客户端版本:version.Info {Major:"1",Minor:"0",GitVersion:"v1.0.4",GitCommit:"65d28d5fd12345592405714c81cd03b9c41d41d9",GitTreeState:"clean"}
服务器版本:version.Info {Major:"1 ",轻微:"2",GitVersion:"v1.2.0",GitCommit:"5cb86ee022267586db386f62781338b0483733b3",GitTreeState:"clean"}

kubernetes

5
推荐指数
1
解决办法
7579
查看次数

将文件从一个Zip文件复制到另一个Zip文件中

我们正在努力从Maven迁移到Gradle.不幸的是,我们仍然需要处理几个War叠加.

作为一种解决方法,我试图将一个war文件的内容复制到另一个war文件中.

这是我到目前为止:

task overlayWars (dependsOn: war) << {
    // Get the source war files to copy the contents from...
    def dependencyWars = configurations.runtime.filter { it.name.endsWith ('.war') }
    dependencyWars.each { dependentWar ->

        // Get the products, ie the target war file...
        war.outputs.files.each { product ->
            println "Copying $dependentWar contents into $product"
            copy {
                from { zipTree (dependentWar) }
                into { zipTree (product)}   // this seems to be the problem
                include 'WEB-INF/classes/**/*.class'
                include 'WEB-INF/jsp/**/*.jsp'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

什么时候into { …

gradle

4
推荐指数
1
解决办法
4587
查看次数

标签 统计

spring ×3

groovy ×2

spring-boot ×2

gradle ×1

java ×1

kubernetes ×1

rest ×1

spring-mvc ×1