0

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

有没有办法用spring bean更改这段代码,因为我将在不同的类中使用这个会话,最好是单例。

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();
4

1 回答 1

1

只需将其声明为 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;
}

所以你可以在任何你需要的地方注入这个会话bean。

于 2017-05-10T14:51:05.193 回答