java - apache 与 spring 的化学 session

标签 java spring alfresco opencmis apache-chemistry

我目前正在开发 java/jee 应用程序,使用 spring 作为框架,使用 alfresco 作为 ged。我正在使用 apache Chemistry 连接到 alfresco 存储库。 这是我用来获取 session 的代码。

有没有办法用 spring bean 更改此代码,因为我将在不同的类中使用此 session ,并且最好是单例。

Map<String, String> parameter = new HashMap<String, String>();

    // user credentials
    parameter.put(SessionParameter.USER, "admin");
    parameter.put(SessionParameter.PASSWORD, "admin");

    // connection settings
    parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    System.out.println(BindingType.ATOMPUB.value());
    // set the alfresco object factory
    parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

    // create session
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Session session = factory.getRepositories(parameter).get(0).createSession();

最佳答案

只需将其声明为 bean:

@Bean
public Session sessionBean() {
    Map<String, String> parameter = new HashMap<String, String>();
    // ...
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Session session = factory.getRepositories(parameter).get(0).createSession();
    return session;
}

因此您可以在任何需要的地方注入(inject)此 session Bean。

关于java - apache 与 spring 的化学 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43895864/

相关文章:

java - 将 long 数组转换为 ArrayList<Long>

java - 如何在发生 mouseReleased 事件时将图像添加到 JPanel

java - 如何让两个不同的端点具有不同的命名空间和相同的 JAXB 类?

spring - 通过 Spring Security 登录后接收 sessionid

java - Alfresco - 基于 Java 的 Webscript - 异步发送响应

java - Java程序如何在虚拟环境中运行Python程序?

java - 创建具有通用类型的 map

java - 什么可能导致 RequestMappingHandlerMapping 无法正确注册?

java - 如何设置 Spring surf 形式 Alfresco 与属性文件中的动态变量共享

java - 露天 : How to filter documents in workflow