我有一个带有RESTful端点的Spring Boot应用程序,我想为joda-time添加自定义序列化程序,但我无法让应用程序默认Jackson serailzier识别我的自定义端口.
我使用@RepositoryRestResource创建了RESTFul端点
@RepositoryRestResource(collectionResourceRel = "x", path = "x")
public interface XRepository extends PagingAndSortingRepository<X, Long>
{
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个GET调用来返回所有对象X:
这是我的序列化器:
@Component
public class JsonDateSerializer extends JsonSerializer<DateTime>
{
private static DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy");
@Override
public void serialize(DateTime value, JsonGenerator gen,
SerializerProvider arg2)
throws IOException, JsonProcessingException {
gen.writeString(formatter.print(value));
}
}
Run Code Online (Sandbox Code Playgroud)
我将它添加到属性Getter,如下所示:
@JsonSerialize(using=JsonDateSerializer.class)
public DateTime getDateCreated()
{
return dateCreated;
}
Run Code Online (Sandbox Code Playgroud)
这个序列化程序在普通应用程序中运行良好,但是当我尝试在Spring Boot应用程序中使用它时,这些序列化程序会被忽略.
如何让Spring Boot识别这些序列化程序?
到目前为止,我一直使用通过Arquillian Testing框架管理的JBOSS AS 7运行我的集成测试.我已经设定了100这已工作正常,但现在我想我的集成测试转移到Wildfly AS管理,但同样的测试失败,出现以下错误偏移:
arquillianBeforeSuite(com.aeroflex.teravm.selfinstall.core.ejb.SampleServiceIT)经过的时间:130.749秒<<<失败!org.jboss.arquillian.container.spi.client.container.LifecycleException:无法启动容器
这是我的Arquillian.xml
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<!-- <defaultProtocol type="Servlet 3.1"/> -->
<container qualifier="wildfly-managed" default="true">
<configuration>
<property name="jbossHome">target/wildfly-8.0.0.Final</property>
<property name="serverConfig">standalone.xml</property>
<property name="outputToConsole">true</property>
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=100</property>
</configuration>
</container>
</arquillian>
Run Code Online (Sandbox Code Playgroud)
以及其中一个集成测试的示例:
public class SampleServiceIT extends BaseServiceIT
{
@Inject
private SampleService sampleService;
@Parameters(ARQUILLIAN_DATA_PROVIDER)
@Test(groups = {"integration"})
public void testGetNotExisting() throws ServiceException
{
Long id = new Long(5);
SampleBean result = sampleService.getSampleObjectById(id);
Assert.assertNull(result);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我不更改端口偏移量并保留默认值,则可以正常工作.
在此先感谢您的帮助.
我是 GraphQL 的新手,我正在尝试弄清楚如何以编程方式发送我在单独的微服务中实现的 GraphQL POST 查询。
\n\n在我的主应用程序中,我使用 Java + Spring REST 模板发送查询,同时将 POST 正文附加为字符串 GraphQL 查询,例如
\n\nString body = "query MyLearner {learner(id: 1) {lastName givenName} learners { givenName }}";\n
Run Code Online (Sandbox Code Playgroud)\n\n我可以在 play-scala 微服务中接收查询,但无法解析 JSON。
\n\n接收方式:
\n\ndef graphqlBody(tenant: Int) = Action.async(parse.json) { request \xe2\x87\x92\n val query = (request.body \\ "query").as[String]\n val operation = (request.body \\ "operationName").asOpt[String]\n\n val variables = (request.body \\ "variables").toOption.flatMap {\n case JsString(vars) \xe2\x87\x92 Some(parseVariables(vars))\n case obj: JsObject \xe2\x87\x92 Some(obj)\n case _ \xe2\x87\x92 None\n }\n\n …
Run Code Online (Sandbox Code Playgroud) graphql ×1
java ×1
jboss7.x ×1
jodatime ×1
json ×1
scala ×1
spring-boot ×1
spring-mvc ×1
testng ×1
wildfly-8 ×1