This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
I have a class defined as follows:
@Component @Service public class CalendarServiceImpl implements CalendarService { static private final org.slf4j.Logger logger = LoggerFactory.getLogger(CalendarServiceImpl.class); @Reference private SlingRepository repository; public void bindRepository(SlingRepository repository) { this.repository = repository; } private Session _session; private Session getSession() { if (_session == null || !_session.isLive()) { try { _session = this.repository.loginAdministrative(null); } catch (RepositoryException e) { logger.error(e.getMessage()); } } return _session; } }
When i try to instantiate the class using the following code from a JSP:
CalendarService calendarService = sling.getService(CalendarService.class);
And call a method which uses the Session variable, i receive and error telling me that the "repository" variable is NULL and therefore the component doesn't function as intended.
The strangest part about this is that it works fine on our Author instance, but doesn't work on the Publish instance.
Any help would be appreciated.
Solved! Go to Solution.
Views
Replies
Total Likes
Do you use the maven-scr-plugin to translate the annotations properly to meta information for the bundle?
Btw: in your code you don't need the bindRepository method, as it you just explicitly stated the default implementation for it :-)
Jörg
Views
Replies
Total Likes
To get a Session within an OSGi bundle, you should inject a ResourceResolver into your bundle:
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html
Hope this helps.
Views
Replies
Total Likes
Do you use the maven-scr-plugin to translate the annotations properly to meta information for the bundle?
Btw: in your code you don't need the bindRepository method, as it you just explicitly stated the default implementation for it :-)
Jörg
Views
Replies
Total Likes
Views
Likes
Replies