我需要根据不同的当前环境配置文件编写不同的逻辑.如何从Spring获取当前的活动和默认配置文件?
文档http://code.google.com/chrome/devtools/docs/elements.html表示它支持XPath或CSS选择器,但是当我尝试时,似乎对我不起作用.
谁知道如何使用它?
代码段:
@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) 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) 我的控制器方法是返回a ModelAndView,但是还需要将cookie写回客户端.是否可以在Spring中完成?谢谢.
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.xml在WEB-INF/classes/META-INF文件夹中.部署时,它只是告诉我
"警告:无法找到文件(忽略):file:.../../lib/app-services-1.0.jar".
我也试过,我能想到的,即每一个可能的路径../lib/app-services-1.0.jar,LIB /应用服务-1.0.jar.
这样做的正确途径是什么?
这将有效:
@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".
有什么建议?
谢谢!
我已将配置日志配置为控制台和日志文件.在heroku世界中,记录到文件是否有意义?有什么方法可以检索日志文件吗?
看起来像json默认编码是UTF-8 Spring mvc默认返回"application/json; charset = utf-8"并且很难改变它.
spring-mvc ×5
content-type ×2
json ×2
cookies ×1
dom ×1
github ×1
heroku ×1
hibernate ×1
http ×1
http-headers ×1
jackson ×1
java ×1
java-ee-6 ×1
jpa ×1
logging ×1
persistence ×1
spring ×1
spring-boot ×1
war ×1
wiki ×1