1

尝试在 Fuse Servicemix(版本 4.3.1)中使用 bean 文件部署战争。我正在使用 Maven 来构建我的战争。我似乎无法让它工作。谁能提供一个可以告诉我如何做到这一点的网站?

这个网站告诉我在 web.xml 文件中放什么,但没有解释其余的。

http://fusesource.com/docs/esbent/7.0/esb_deploy_osgi/BuildWar-Spring.html

在 19 天的时间里,我尝试了几种解决方案和方法。每个人似乎对这只猫的皮肤都不一样,但它们都不适合我。

脂肪战争(已解决)

请看下面的答案


瘦身战

在osgi中似乎是不可能的。需要手动导入太多包。这个链接似乎可以解决它,但似乎有很多讨厌的副作用。

http://davidvaleri.wordpress.com/2011/08/17/deploying-spring-mvc-based-web-applications-to-osgi-using-apache-servicemix/

4

2 回答 2

0

您需要将 Spring OSGi ContextLoaderListener 添加到您的 web.xml 中,否则它不起作用。您还需要 Spring-DM 1.2.1 的依赖项。查看Pax Web Spring 示例,尤其是其中的 web.xml。这是一个关于如何在 Karaf / Fuse-ServiceMix 中使用 Spring 的工作示例......

我想我给你指出了错误的样本。您不需要使用以下内容。

contextClass
org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext

于 2013-04-05T10:13:56.400 回答
0

脂肪战争解决方案

这是对我有用的最小可行解决方案。我试图删除一些东西,但它很快就坏了,通常甚至没有发布错误消息。


目录结构:

src/main/java/test/Test.java
src/main/webapp/WEB-INF/web.xml
src/main/webapp/WEB-INF/applicationContext.xml

pom.xml

...
    <groupId>test</groupId>
    <artifactId>war-bean-test</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework.osgi</groupId>
          <artifactId>spring-osgi-web</artifactId>
          <version>1.2.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <executions>
                  <execution>
                    <id>bundle-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                      <goal>manifest</goal>
                    </goals>
                  </execution>
                </executions>
                <configuration>
                  <supportedProjectTypes>
                    <supportedProjectType>jar</supportedProjectType>
                    <supportedProjectType>bundle</supportedProjectType>
                    <supportedProjectType>war</supportedProjectType>
                  </supportedProjectTypes>
                  <instructions>
                    <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>

                    <!-- IMPORTANT resolution:=optional fixes bug where bundle fails to load unnecessary packages such as bsh. You also need javax.servlet. In Servicemix 4.3.1 it is provided by geronimo servlet. -->
                    <Import-Package>
                        javax.servlet
                        *; resolution:=optional
                    </Import-Package>
                    <Export-Package></Export-Package>

                    <!-- IMPORTANT explicitly adding the jars fixes the numerous CassNotFoundExceptions -->
                    <Bundle-ClassPath>
                        .,WEB-INF/classes,{maven-dependencies}
                    </Bundle-ClassPath>
                    <Web-ContextPath>warbeantest</Web-ContextPath>
                    <Webapp-Context>warbeantest</Webapp-Context>

                    <!-- adding inline=true to Embed-Dependency causes {maven-dependencies} to not work and you will have to add every jar by hand -->
                    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                    <Embed-Directory>WEB-INF/lib</Embed-Directory>
                  </instructions>
                </configuration>
              </plugin>

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                  <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                  </archive>
                </configuration>
              </plugin>
        </plugins>
    </build>
</project>

web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
    <display-name>war-bean-test</display-name>
    <description>war-bean-test</description>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <!-- If you remove this then the spring beans will still work, but you wont be able to fetch services and resources from other osgi bundles -->
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

应用程序上下文.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="test" class="test.Test">
        <property name="value" value="1" />
    </bean>
</beans>

测试.java

package test;
public class Test {
    private int value = 0;
    public TestImpl() { }

    public void setValue(int value) {
        // Should print to console when you load into Fuse Servicemix
        System.out.println("testing...");
        this.value = value;
    }

    public int getValue() { return value; }
}
于 2013-04-20T01:50:21.657 回答