Hi Everyone,
I am trying to connect to MS SQL database in AEM 5.6 . Below is my service class which will provide the connection.
@Component
@Service
public class JDBCConnectionServiceImpl implements JDBCConnectionService{
private static final Logger LOGGER =
LoggerFactory.getLogger(JDBCConnectionServiceImpl.class);
private static String DATA_SOURCE_NAME="sqljdbc";
@Reference
private DataSourcePool source;
public Connection getConnection() {
Connection con=null;
try {
DataSource ds = (DataSource) this.source.getDataSource(DATA_SOURCE_NAME);
con= ds.getConnection();
}catch(Exception e){
LOGGER.error("Exception when getting the setting data source ",e);
}
return con;
}
public void closeConnection(Connection connection) {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOGGER.error("Exception when trying to close the connection {} ",e);
}
}}
When I try to access this service it throws a class not found exception as shown
java.lang.ClassNotFoundException: mypackage.JDBCConnectionServiceImpl not found by mypackage [377]
at java.lang.Throwable.<init>(Throwable.java:80)
at java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:76)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1420)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1923)
But when I access the same data source in component JSP as shown below it is working fine
DataSourcePool dspService = sling.getService(DataSourcePool.class);
DataSource ds = (DataSource) dspService.getDataSource("sqljdbc");
Not sure what is the problem with OSGi Service.
Help me on this please.
Regards,
Krishna
Solved! Go to Solution.
When creating the Maven project - try placing the interface and imlp class in the same AEM package. Then delete all other generated Maven Java files.
Hi,
first,Here is the complete article on Adobe site: https://helpx.adobe.com/experience-manager/using/persisting-cq-data-relational-database.html
second, did your build got successful when you deployed in AEM 5.6.1?
Ensured that your bundle STARTED once it is deployed in AEM 5.6.1.
Views
Replies
Total Likes
Hi ,
Thanks for the reply.
I have went through the article already.
I have different bundles deployed for my project and ms sql drivers. Both are build successfully.D
When I deploy the project bundle it throws Impl class not found exception as mentioned in the post. Still both the bundles are active in felix.
Thanks,
Krishna
Views
Replies
Total Likes
Its seems to be the simple case where AEM is not able to find you class although as you mentioned build is successful,
Can you check in your pom.xml that the packages in which this class is present is in <export-package> section.
Views
Replies
Total Likes
Export package details are fine. Even though the build is successful when I deploy it throws a exception as mentioned.
I think there might be problem with OSGi configuration which I am not aware like binding datasourcepool before the service starts (Just a thought)
Thanks.
Krishna
Views
Replies
Total Likes
When creating the Maven project - try placing the interface and imlp class in the same AEM package. Then delete all other generated Maven Java files.
Thanks Scott,
It is working fine now .But the other services works fine without having the implementation and interface in the same package .
Is this a restriction while using DataSourcePool ?
Is there any way to encrypt the password available in DataSourcePool OSGi Configuration ?
Thanks,
Krishna
Views
Replies
Total Likes
From your error - it looked like there was an issue finding the Imlp class. I find this happens sometimes and this is the fix i use.
Views
Replies
Total Likes
Thanks Scott
Views
Replies
Total Likes