我是一个完整的newb,所以我提前致歉。我正在尝试创建一个OSGi组件,该组件只显示hello world消息,并可通过felix的输入进行配置。然后吐出一个jsp页面。我正在使用scr注释来帮助做到这一点。这是我的Java代码OSGi组件可通过Apache Felix配置
package com.training.cq5.trainingApp;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import org.apache.sling.commons.osgi.PropertiesUtil;
@Component(label= "Welcome Message",
description = "Welcome Message for the training excercise",
immediate = true, enabled = true, metatype=true)
@Properties({
@Property(name = "welcome.message", value = "WelcomeMessage")
})
@Service(WelcomeMessage.class)
public class WelcomeMessage {
private static String welcome_message = "Welcome";
@Activate
protected void activate(ComponentContext ctx) {
welcome_message = PropertiesUtil.toString(ctx.getProperties().get(welcome_message), welcome_message);
}
public static String getMessage() {
return welcome_message;
}
}
这里是被我称之为在JSP:
<%@ page import="com.training.cq5.trainingApp.WelcomeMessage" %>
<h2><%= WelcomeMessage.getMessage() %></h2>
是否有任何理由为什么它不从菲利克斯更新?我所得到的是welcome_message字符串中的“Welcome” 文本。
T hanks @ilikeorangutans。我确实安装并运行了Apache Felix SCR插件。那么我的问题就在于通过吊索访问它?对不起,我是一个完整的,我的意思是完整的newb在这里。任何修改我的代码将不胜感激。或者任何代码示例都会有很大帮助。谢谢! –
谢谢@ilikeorangutans。任何想法为什么我在添加你的JSP时遇到这个错误。 ** SlingBindings无法解析为类型** –
您错过了您网页中的相应导入:<%@ page import =“org.apache.sling.api.scripting.SlingBindings”%> – ilikeorangutans