小编ran*_*m86的帖子

从DB中删除cascade和orphan有什么区别?

有什么区别

@OneToMany(cascade=REMOVE, mappedBy="customer")
public List<Order> getOrders() { ... }
Run Code Online (Sandbox Code Playgroud)

@OneToMany(mappedBy="customer", orphanRemoval="true")
public List<Order> getOrders() { ... }
Run Code Online (Sandbox Code Playgroud)

这个例子来自Java EE Tutorial,但我仍然不了解细节.

java jpa cascading-deletes

88
推荐指数
5
解决办法
7万
查看次数

用json身体摇摆POST

我正在尝试使用swagger编写服务器响应的静态.json文件.我被贴在身体上,不知道如何描述它.它看起来非常类似于Grooveshark api,你有一个页面和不同的帖子参数.

所以,给出了groovehark的例子(http://developers.grooveshark.com/docs/public_api/v3/)

接受查询的页面:

http://api.grooveshark.com/ws3.php?sig=cd3ccc949251e0ece014d620bbf306e7
Run Code Online (Sandbox Code Playgroud)

POST机构:

{'method': 'addUserFavoriteSong', 'parameters': {'songID': 0}, 'header': {'wsKey': 'key', 'sessionID': 'sessionID'}}
Run Code Online (Sandbox Code Playgroud)

我怎么能用昂首阔步来描述这个?

json swagger

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

如何对 dropwizard 服务器资源进行集成测试?

我正在编写 dropwizard 应用程序,并且坚持进行集成测试。我试图pre-integration-test在 maven 阶段启动服务器,而不是在post-integration-test阶段停止它,但问题是我在使用 maven-exec 插件时丢失了 java 线程。配置如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>create-and-run-dropwizard-test-server</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
           <argument>-jar</argument>
           <argument>target/my-server.jar</argument>
           <argument>server</argument>
           <argument>test-config.yml</argument>
        </arguments>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

使用它 maven 运行直到pre-integration-test阶段,然后在同一线程中启动服务器。无论如何,我可以将它作为 bash 脚本运行,而不是使用kill -9命令停止它,但此解决方案不是平台独立的。

还有其他方法可以进行集成测试吗?PS 我正在使用 dropwizard v0.7.0-SNAPSHOT。

java integration-testing maven dropwizard

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

在Spring 4.1.3中注册ObjectMapper以序列化Joda DateTime

我正在尝试在我的Web应用程序中配置ObjectMapper以序列化/反序列化以ISO 8601格式呈现为Joda的DateTime的日期.我找到了有用的库jackson-datatype-joda和它的模块,JodaModule所以我添加了依赖:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-joda</artifactId>
    <version>2.4.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我的Spring配置:

<bean id="objectMapper"
    class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
    p:indentOutput="true">

    <property name="featuresToDisable">
        <array>
            <util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS" />
        </array>
    </property>

    <property name="modulesToInstall" value="com.fasterxml.jackson.datatype.joda.JodaModule" /> 
</bean>

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="objectMapper" />
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
Run Code Online (Sandbox Code Playgroud)

当我尝试序列化这个bean时

public class Bean {
    private DateTime start = new DateTime();

    public DateTime getStart() { return start; }
    public void setStart(DateTime start) { this.start = start; }        
}
Run Code Online (Sandbox Code Playgroud)

我得到以下输出,但希望它是ISO 8601格式:

{"start":1418337158933}

我发现JodaModule如果在类路径中找到它也会预加载,因此无需手动注册它(请参阅github repo),但在应用程序启动期间会多次调用此代码.

我认为原因是ObjectMapper在其他地方实例化. …

java datetime spring-mvc jodatime jackson

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

如何使用Arquillian测试RESTful方法?

我有一组用于在项目中使用REST方法的类.它们看起来像这样:

@Path("customer/")
@RequestScoped
public class CustomerCollectionResource {

    @EJB
    private AppManager manager; // working with DB

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response list(@QueryParam("email") String email) {
        final List<Customer> entities = manager.listCustomers(email);
        // adding customers to result
        return Response.ok(result).build();
    }
}
Run Code Online (Sandbox Code Playgroud)

之后我写了测试方法:

@RunWith(Arquillian.class)
public class CustomerResourceTest { 

@Deployment
public static WebArchive createTestArchive() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
        // Adding omitted                                
        //.addClasses(....)                 
    }   

    @Test @GET @Path("projectName/customer") @Consumes(MediaType.APPLICATION_JSON)
    public void test(ClientResponse<List<Customer>> response) throws Exception {
    assertEquals(Status.OK.getStatusCode(), response.getStatus());      
    }
}
Run Code Online (Sandbox Code Playgroud)

尝试运行此测试时,我得到NullPointerException.这是因为测试用例中的空响应.为什么会这样?DB配置正确.

rest unit-testing java-ee jboss-arquillian

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

Spring Webflux OAuth 2 资源服务器

我有一个基于 Spring Boot 1.5 (Spring Security v4) 的 Spring OAuth 2 服务器,它生成定制的令牌和一些与这个授权服务器通信的资源服务器,/oauth/check_token通过配置使用端点RemoteTokenServices。与在授权服务器端存储/检索令牌相关的所有逻辑都使用JdbcTokenStore.

我正在构建一个新的 Spring Boot 2 应用程序,它是用 Spring webflux 模块构建的,并尝试client_credentials使用 Spring Security 5.1.1实现与现有授权服务器的流程。我发现在 5.1.0.RC1 ( https://spring.io/blog/2018/08/21/spring-security-5-1-0-rc1-released#oauth2-resource-服务器)并在 5.1.0.RC2 中更新(https://spring.io/blog/2018/09/10/spring-security-5-1-0-rc2-released#oauth2-resource-server)但看起来像只能使用 JWT 支持对其进行配置。

我可能在这里弄乱了概念,但正在寻找更多信息以及将所有这些组件配置在一起的方法。

spring spring-security jwt spring-boot spring-security-oauth2

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

Java Regex用于更改字符串中每个单词的每个第i个索引

我写了一个正则表达式\b\S\w(\S(?=.))来查找单词中的每个第三个符号,并将其替换为"1".现在我正在尝试使用这个表达式,但实际上不知道如何正确使用它.

Pattern pattern = Pattern.compile("\\b\\S\\w(\\S(?=.))");
Matcher matcher = pattern.matcher("lemon apple strawberry pumpkin");

while (matcher.find()) {
    System.out.print(matcher.group(1) + " ");
}
Run Code Online (Sandbox Code Playgroud)

结果是:

m p r m
Run Code Online (Sandbox Code Playgroud)

我怎么能用它来制作这样的字符串呢

le1on ap1le st1awberry pu1pkin
Run Code Online (Sandbox Code Playgroud)

java regex

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