我正在尝试在我的grails项目中实现Sling Servlet,基于以下http://sling.apache.org/documentation/the-sling-engine/servlets.html
在Pom.xml中,添加了以下依赖项
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.6.0</version>
</dependency>
根据一些研究,还添加了以下插件
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.9.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
在BuildConfig.groovy中,下面的行添加在依赖项下。
compile "org.apache.felix:org.apache.felix.scr.annotations:1.6.0"
runtime "org.apache.felix:org.apache.felix.scr.annotations:1.6.0"
compile "org.apache.sling:org.apache.sling.api:2.8.0"
runtime "org.apache.sling:org.apache.sling.api:2.8.0"
Amd My Sling Servlet看起来像这样,
@SlingServlet(resourceTypes = "/slingsamples",
selectors = "hello",
extensions = "html",
methods = "GET,POST",
name="com.servlets.SlingCharts")
public class SlingCharts extends SlingAllMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/plain");
response.getOutputStream().print("Hello World!");
}
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/plain");
response.getOutputStream().print("Hello World!");
}
}
我尝试使用http://localhost:8080/app_name/slingsamples
调用我的servlet它给予&#34;未找到&#34;错误。
使用SlingServlet注释,Servlet是自动注册还是我需要在某处明确提及。如果是这样,如何在我的grails应用程序中这样做。
在研究期间,许多人告诉他们配置Apache Sling Servlet /资源解析器在OSGI控制台/ system / console / configMgr中并添加执行路径的路径。
在我的情况下是否真的需要,如果是这样,如何使用grails来实现。
还有其他方法可以在grails中处理这个/ access slingservlet。
请帮助解决此问题。
注意:我使用的是STS IDE。