小编DCO*_*DCO的帖子

在Wildfly上使用Primefaces Fileupload

我想在数据库中保存配置文件图像.

页:

<p:graphicImage id="profileImage"
                        value="#{myProfile.usersProfileImage}" />    
<p:fileUpload fileUploadListener="#{myProfile.fileUploadListener}"
                            auto="true" mode="advanced" update="profileImage"
                            sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
Run Code Online (Sandbox Code Playgroud)

后盾:

public StreamedContent getUsersProfileImage() {
            return new DefaultStreamedContent(new ByteArrayInputStream(
                    user.getProfileJpegImage()));
    }    
public void fileUploadListener(FileUploadEvent event) {
        try {
            setProfileImageFromInputStream(event.getFile().getInputstream());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    private void setProfileImageFromInputStream(InputStream stream) {
        try {
            user.setProfileJpegImage(IOUtils.toByteArray(stream));
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
Run Code Online (Sandbox Code Playgroud)

选择图片后,图片不会改变,我的控制台出现以下错误

14:36:02,387 ERROR [io.undertow.request] (default task-2) UT005005: Cannot remove uploaded file C:\Development\wildfly-8.0.0.Final\standalone\tmp\myApp.war\undertow3307538071115388117upload
Run Code Online (Sandbox Code Playgroud)

我也发现了这个问题 https://issues.jboss.org/browse/WFLY-2329

我还尝试使用multipart-config来扩展我的Faces Servlet,例如:

<servlet>
        <servlet-name>Faces Servlet</servlet-name> …
Run Code Online (Sandbox Code Playgroud)

primefaces jsf-2.2 wildfly

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

在 Spring Boot 中使用嵌入式 MongoDB 测试 @Transactional

我想确保 @Transactional 注释有效,所以我编写了一个保存和发布文章的测试 - 我的 kafka 发布者是一个模拟,它在任何调用时抛出异常。我想确保 MongoDB 回滚持久化的文章。

@Test
void testRollbackOnPublishFail() {
    when(producer.publishArticle(any())).thenThrow(IllegalStateException.class);
    ArticleDocument articleDocument = ArticleTestDataUtil.createArticleDocument();
    try {
        ArticleDocument publishedDocument = articleService.saveAndPublish(articleDocument);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalStateException);
    }
    assertFalse(articleService.findById(articleDocument.getId()).isPresent());
}
Run Code Online (Sandbox Code Playgroud)

我正在使用嵌入式 mongo db 进行集成测试

 testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.2.0"
Run Code Online (Sandbox Code Playgroud)

此测试失败,因为默认情况下没有事务/复制。

因此通过创建 MongoTransactionManager 激活事务:

@Configuration
public class MongoTransactionConfig {

    @Bean
    public MongoTransactionManager transactionManager(MongoDbFactory dbFactory) {
        return new MongoTransactionManager(dbFactory);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我的测试失败了,因为无法在 MongoClient 中启动会话

com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected
        at …
Run Code Online (Sandbox Code Playgroud)

spring mongodb spring-boot

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

标签 统计

jsf-2.2 ×1

mongodb ×1

primefaces ×1

spring ×1

spring-boot ×1

wildfly ×1