fbm fatma
fbm fatma

Reputation: 450

apache chemistry session with spring

I am currently developping java/jee app using spring as framework and alfresco as ged. I am using apache chemistry to connect to the alfresco repository. This the code I am using to get a session.

Is there a way to change this code with spring bean because I`m going to use this session in diffrent classes and it would be better to be singleton.

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

Upvotes: 0

Views: 842

Answers (1)

Bogdan Kobylynskyi
Bogdan Kobylynskyi

Reputation: 1220

Just declare it as a 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;
}

So you can inject this session bean wherever you need.

Upvotes: 1

Related Questions