小编Bob*_*obo的帖子

如何在Spring中以编程方式获取当前活动/默认环境配置文件?

我需要根据不同的当前环境配置文件编写不同的逻辑.如何从Spring获取当前的活动和默认配置文件?

java spring spring-profiles

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

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

如何将附件上传到GitHub wiki?

我知道如何从维基引用它,但在GitHub网站上我是否上传附件?非常感谢!

wiki github

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

Http Post请求内容类型表单在Spring MVC 3中不起作用

代码段:

@RequestMapping(method = RequestMethod.POST)//,  headers = "content-type=application/x-www-form-urlencoded")
public ModelAndView create(@RequestBody UserAccountBean account) {
    try{
        accounts.put(account.assignId(), account);
    }catch(RuntimeException ex)
    {
        return new ModelAndView("account/registerError");
    }
    return new ModelAndView("account/userVerification");
}
Run Code Online (Sandbox Code Playgroud)

收到请求后,我得到的是Http状态代码415:服务器拒绝了此请求,因为请求实体的格式不受所请求方法所请求资源的支持().

如果我将代码更改为:

代码段:

@RequestMapping(method = RequestMethod.POST,headers = "content-type=application/x-www-form-urlencoded")
public ModelAndView create(@RequestBody UserAccountBean account) {
    try{
        accounts.put(account.assignId(), account);
    }catch(RuntimeException ex)
    {
        return new ModelAndView("account/registerError");
    }
    return new ModelAndView("account/userVerification");
}
Run Code Online (Sandbox Code Playgroud)

我将不允许405方法.有趣的是在允许的响应标题中,它将GET和POST列为允许的方法.

我有一个做JOSN映射的类:

@Component
public class JacksonConversionServiceConfigurer implements BeanPostProcessor {

private final ConversionService conversionService;

@Autowired
public JacksonConversionServiceConfigurer(ConversionService conversionService) {
    this.conversionService = conversionService;
}

public Object postProcessBeforeInitialization(Object …
Run Code Online (Sandbox Code Playgroud)

content-type spring-mvc

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

如何配置spring mvc 3在json响应中不返回"null"对象?

json响应的示例如下所示:

{"publicId":"123","status":null,"partner":null,"description":null}
Run Code Online (Sandbox Code Playgroud)

截断响应中的所有空对象会很好.在这种情况下,响应将变为{"publicId":"123"}.

有什么建议?谢谢!

PS:我想我可以在泽西岛做到这一点.另外我相信他们都使用Jackson作为JSON处理器.

后来添加:我的配置:

<?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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="com.SomeCompany.web" />

    <!-- Application Message Bundle -->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="/WEB-INF/messages/messages" />
        <property name="cacheSeconds" value="0" />
    </bean>

    <!-- Configures Spring MVC -->
    <import resource="mvc-config.xml" />
Run Code Online (Sandbox Code Playgroud)

<?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:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- Configures the @Controller programming model …
Run Code Online (Sandbox Code Playgroud)

json spring-mvc jackson

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

在spring mvc 3中,如何在返回ModelAndView时编写cookie?

我的控制器方法是返回a ModelAndView,但是还需要将cookie写回客户端.是否可以在Spring中完成?谢谢.

cookies spring-mvc spring-boot

26
推荐指数
3
解决办法
4万
查看次数

在Web应用程序中引用jpa persistence.xml中的jar文件的正确途径是什么?

persistence.xml看起来像这样:

<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>jdbc/test</non-jta-data-source>
    <jar-file>../../lib/app-services-1.0.jar</jar-file>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

它是一个Web项目,因此部署单元是一个war文件.我试图引用的jar文件在WEB-INF/lib /文件夹中,persistence.xmlWEB-INF/classes/META-INF文件夹中.部署时,它只是告诉我

"警告:无法找到文件(忽略):file:.../../lib/app-services-1.0.jar".

我也试过,我能想到的,即每一个可能的路径../lib/app-services-1.0.jar,LIB /应用服务-1.0.jar.

这样做的正确途径是什么?

persistence hibernate jpa war java-ee-6

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

Spring MVC @RequestMapping标头只能接受一个值吗?

这将有效:

@RequestMapping(value = "/test", method = RequestMethod.POST,
    headers = {"content-type=application/json"}) {
    .......
}
Run Code Online (Sandbox Code Playgroud)

如果我像下面那样添加另一个值,那么它将失败并告诉我:

请求的资源不允许使用指定的HTTP方法(不支持请求方法'POST')

@RequestMapping(value = "/test", method = RequestMethod.POST,
    headers = {"content-type=application/json","content-type=application/xml"}) {
    .......
}
Run Code Online (Sandbox Code Playgroud)


我想这是因为Spring认为两个内容类型值具有"AND"关系,但我希望它们是"OR".

有什么建议?

谢谢!

content-type spring-mvc http-headers

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

heroku中的日志文件在哪里?

我已将配置日志配置为控制台和日志文件.在heroku世界中,记录到文件是否有意义?有什么方法可以检索日志文件吗?

logging heroku

17
推荐指数
2
解决办法
7403
查看次数

为什么内容类型标头用于json?"application/json; charset = utf-8"或"application/json"?

看起来像json默认编码是UTF-8 Spring mvc默认返回"application/json; charset = utf-8"并且很难改变它.

json http spring-mvc

15
推荐指数
1
解决办法
3万
查看次数