Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

@Reference in sightly

Avatar

Avatar
Validate 1
Level 2
naniv22657571
Level 2

Likes

4 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
naniv22657571
Level 2

Likes

4 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
naniv22657571
Level 2

11-05-2016

Hello All,

I wrote onc java class which extends to WCMUse,i am trying to use ResourceResolverFactory using @Reference but factory object is getting null even i made this as commponent @Component;

I know it is depricated.

 

Public class Test extends WCMUse{

@Reference

 ResourceResolverFactory factory;

void    activate(){

}

ResourceResolver getResourceResolver(){

 

 return factory.getAdminstrativResourceResolver(null);

}

 

 @Reference can wont work in sightly ?

I appreciate some one respond asap.

 

Thanks,

Nani.

Replies

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

11-05-2016

You cannot use @Reference in a Sightly Java class. Best way is to use sling model with Sightly and use @osgiservice for injection. See:  https://sling.apache.org/documentation/bundles/models.html

Avatar

Avatar
Validate 1
Level 2
naniv22657571
Level 2

Likes

4 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
naniv22657571
Level 2

Likes

4 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Affirm 1
View profile
naniv22657571
Level 2

11-05-2016

Thank you very much.smacdonald2008

Avatar

Avatar
Validate 10
Level 6
leeasling
Level 6

Likes

73 likes

Total Posts

292 posts

Correct Reply

75 solutions
Top badges earned
Validate 10
Validate 1
Boost 50
Boost 5
Boost 3
View profile

Avatar
Validate 10
Level 6
leeasling
Level 6

Likes

73 likes

Total Posts

292 posts

Correct Reply

75 solutions
Top badges earned
Validate 10
Validate 1
Boost 50
Boost 5
Boost 3
View profile
leeasling
Level 6

12-05-2016

You can also use the Sling Script Helper

private MyService myService; @Override public void activate() throws Exception { myService = this.getSlingScriptHelper().getService(MyService.class); }

Avatar

Avatar
Ignite 1
Level 2
Rajashankar
Level 2

Likes

5 likes

Total Posts

22 posts

Correct Reply

2 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 3
Give Back
Boost 5
View profile

Avatar
Ignite 1
Level 2
Rajashankar
Level 2

Likes

5 likes

Total Posts

22 posts

Correct Reply

2 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 3
Give Back
Boost 5
View profile
Rajashankar
Level 2

12-08-2017

Adding to original post for reference of developers who is using osgi service call in sightly

a) you need to add below dependency in maven bundle/pom.xml for WCMUse class

<dependency>

                <groupId>com.adobe.aem</groupId>

                <artifactId>aem-api</artifactId>

                <version>6.0.0.1</version>

                <scope>provided</scope>

            </dependency>

b) Next  important one to be considered is need to mention the package of Bundle in bundle/pom.xml under plugin section as shown below else you will get class not found exception when you try to reference the bundle in WCMUse  extension class.

  <plugin>

                <groupId>org.apache.felix</groupId>

                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>

                <configuration>

                    <instructions>

                        <Bundle-SymbolicName>com.aem.community.mybundle</Bundle-SymbolicName>

                        <Export-Package>

               <!-- Let's export our primary package below is important else you will get class not found exception for youre bundle -->

               com.aem.community,

               com.aem.community.impl

                <!-- By default, don't export any other packages -->

            </Export-Package>

                       

                    </instructions>

                </configuration>

            </plugin>