I am trying to get a system user session in Sling Model by using @inject ResourceResolverFactory .I am getting below error
org.apache.sling.api.resource.LoginException: Cannot derive user name for bundle org.apache.sling.models.impl  and sub service
But i am able to get the session if i add the same session logic to a @Component class and inject this component into my sling bundle. So there is no issue with System user account setup.Issue is with injection.
Below is my code for sling model to get system user:
your problem is that a sling model runs in the scope of the sling scripting bundle (at least in the context of the determination of service users), and the sling scripting bundle does not provide a system user for your case.
A OSGI component always runs in the context of the bundle it is part of, and in that case the lookup of the system user works.
So you don't see a bug but intended behavior.
Anyways, in my point of view a Sling model should not contain too much logic; in the end it's a model for a frontend component, and therefor the session you have at hand should be sufficient. If you need to use a system user session to perform activities which are not possible to do with the permissions of the user executing the request, you should move this into an OSGI service/component.