Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ApacheKaraf不加载spring应用程序上下文_Spring_Osgi_Apache Karaf - Fatal编程技术网

ApacheKaraf不加载spring应用程序上下文

ApacheKaraf不加载spring应用程序上下文,spring,osgi,apache-karaf,Spring,Osgi,Apache Karaf,我正在尝试编写一个spring应用程序osgi包,它将部署在ApacheKaraf中。我的捆绑包成功生成,当我在Karaf中安装捆绑包时,它显示捆绑包已成功启动,并且相应的捆绑包状态为“已解决”。但我不相信捆绑包已经成功启动 因为出于测试目的,我的一个Springbean实现了InitializingBean,在afterPropertiesSet方法中,我只放了一个sysout。这意味着在加载应用程序上下文时,应该在karaf控制台中打印sysout 但事实并非如此。 应用程序上下文文件位于s

我正在尝试编写一个spring应用程序osgi包,它将部署在ApacheKaraf中。我的捆绑包成功生成,当我在Karaf中安装捆绑包时,它显示捆绑包已成功启动,并且相应的捆绑包状态为“已解决”。但我不相信捆绑包已经成功启动

因为出于测试目的,我的一个Springbean实现了InitializingBean,在afterPropertiesSet方法中,我只放了一个sysout。这意味着在加载应用程序上下文时,应该在karaf控制台中打印sysout

但事实并非如此。 应用程序上下文文件位于
src/main/resources/META-INF/spring
目录下,并且在清单文件中添加了spring上下文标记。但它仍然不能正常工作

我是OSGI的新手,已经坚持了三天多了。我关注了文档和谷歌搜索结果,但仍然没有运气

请在这方面帮助我。我还附加了我的小代码库在这里,以便您可以看看它

我的应用程序上下文

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p = "http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd 
        http://www.springframework.org/schema/osgi
        http://www.springframework.org/schema/osgi/spring-osgi.xsd">
    <bean id="newService" class="com.mycompany.bundle.SpringService"/>
    <bean id="springContext" class="com.mycompany.bundle.SpringContext"/>
    <osgi:service id="simpleServiceOsgi" ref="newService"
        interface="com.mycompany.bundle.ISpringService" />
</beans>

我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.shamik</groupId>
    <artifactId>com.shamik.bundle.new</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging>
    <name>com.shamik.bundle.new Bundle</name>
    <description>com.mycompany.bundle OSGi bundle project.</description>
    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.osgi</groupId>
            <artifactId>spring-osgi-core</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.osgi</groupId>
            <artifactId>spring-osgi-extender</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.osgi</groupId>
            <artifactId>spring-osgi-io</artifactId>
            <version>1.2.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                <excludeDependencies>*;scope=provided|runtime</excludeDependencies>
                    <unpackBundle>true</unpackBundle>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
    <!--                <Bundle-Activator>com.mycompany.bundle.Activator</Bundle-Activator> -->
                        <Export-Package>
                            javax.xml.parsers*,org.xml.sax*,com.mycompany.bundle*;version=${project.version},org.springframework.context*,org.springframework.stereotype*
                        </Export-Package>
                        <Import-Package>
                            com.mycompany.bundle*,javax.xml.parsers*,org.xml.sax*,org.springframework.context*,org.osgi*,org.springframework.stereotype*,!*
                        </Import-Package>
                        <Include-Resource>src/main/resources</Include-Resource>
                        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
                        <DynamicImport-Package>*</DynamicImport-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>       
    </build>
</project>

4.0.0
com.shamik
com.shamik.bundle.new
1.0-快照
捆
com.shamik.bundle.new bundle
com.mycompany.bundle OSGi bundle项目。
org.osgi
org.osgi.core
4.2.0
假如
org.springframework.batch
弹簧批芯
2.2.0.1发布
公地郎
公地郎
2.6
org.springframework.osgi
spring osgi内核
1.2.1
org.springframework.osgi
spring osgi扩展器
1.2.1
org.springframework.osgi
春宫
1.2.1
org.apache.felix
maven捆绑插件
2.3.7
真的
*;范围=提供的|运行时
真的
${project.artifactId}
${project.version}
javax.xml.parsers*,org.xml.sax*,com.mycompany.bundle*;version=${project.version},org.springframework.context*,org.springframework.stereotype*
com.mycompany.bundle*,javax.xml.parsers*,org.xml.sax*,org.springframework.context*,org.osgi*,org.springframework.stereotype**
src/main/resources
*;范围=编译|运行时
真的
*;发布上下文:=false;异步创建:=true
*

您需要安装karaf的spring dm功能。它包含一个扩展程序,用于扫描捆绑包中的spring上下文并启动这些上下文。如果没有此选项,捆绑包可能会启动,但不会执行任何操作。

“已解决”并不意味着一切都很好并已启动。这仅仅意味着卡拉夫“找到了你的东西”。如果所有内容都已成功加载并启动,则状态将为“活动”。实际上,您的包是惰性的

您可能需要检查应用程序上下文xml文件的名称是否为默认名称。我原以为该目录中的任何xml文件都会被读入,但您可能希望第一次尝试将其重命名为“spring.xml”。(我使用blueprint配置和jboss karaf构建,所以我不能说这是否有帮助——尽管我怀疑没有)

假设这不是问题所在,请打开2个端子,并:
-首先,启动karaf客户端并执行
log:tail

-在第二步中,启动karaf客户端并执行
restart

-用第一个终端的输出更新帖子

辅助注释-如果您选择采用较新的“blueprint”配置标准(推荐,基本上是spring配置的超集),那么默认文件名/位置是
src/main/resources/OSGI-INF/blueprint/blueprint.xml