我的想法是在测试中创建一个文件然后删除它,但是我的代码失败了
我的代码:
@RunWith(RemoteTestRunner.class)
@Remote(runnerClass=SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:alfresco/application-context.xml")
public class FooTest {
private static final String ADMIN_USER_NAME = "admin";
@Autowired
@Qualifier("NodeService")
protected NodeService nodeService;
@Autowired
private FileFolderService fileFolderService;
@Autowired
protected Repository repositoryHelper;
@Test
public void testCreateTempFile() {
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME);
NodeRef root = repositoryHelper.getSharedHome();
// create the node
// this line throw an exception
FileInfo fileInfo = fileFolderService.create(root,
"foo.txt", ContentModel.PROP_CONTENT);
...
}
}
出现如下错误:
org.alfresco.error.AlfrescoRuntimeException: 07170002 Transaction must be active and synchronization is required: Thread[main,5,main] at org.alfresco.util.transaction.TransactionSupportUtil.registerSynchronizations(TransactionSupportUtil.java:188)
交易如何运作?如何激活它?
最佳答案
为了使用临时文件,alfresco 提供了一个实用类
org.alfresco.util.TempFileProvider
它具有允许您创建临时文件和目录的所有 API。
如果您经常使用临时文件,您甚至可以考虑使用这个 utility这允许您定期清除临时文件。
https://stackoverflow.com/questions/38987588/