2013-04-04 69 views
2

嘗試在Fuse Servicemix(版本4.3.1)中與bean文件部署一場戰爭。我正在使用maven來打造我的戰爭。我似乎無法得到這個工作。任何人都可以提供一個網站,可以告訴我如何做到這一點?全部工作:War,OSGI,Spring Beans,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/

回答

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> 

的applicationContext.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> 

Test.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; } 
} 
0

您需要到春節的OSGi的ContextLoaderListener添加到web.xml否則它不能正常工作。你還需要依賴Spring-DM 1.2.1。 看看Pax Web Spring sample,尤其是web.xml。這是一個關於如何在Karaf/Fuse-ServiceMix中使用Spring的工作示例...

我想我指出了你錯誤的示例。您不需要使用以下內容。

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

+0

阿希姆。我上面提供的鏈接告訴我要包含ContextLoaderListener,所以我很好。我拿你的榜樣試了一下。我刪除了所有jsp的東西,只是使用了一個簡單的網頁。xml與ContextLoaderListener和一個歡迎的index.html頁面。捆綁加載罰款沒有錯誤。但是我的bean中的print語句從不會觸發。將代碼添加到原始帖子。 – Thirlan 2013-04-05 18:06:58

+0

Achim它肯定會跳過我的beans文件。我遠程調試並在我的println上添加了一個換行符。它永遠不會執行。 – Thirlan 2013-04-05 19:56:54

+1

我糾正了上下文類,抱歉是錯誤的示例。 – 2013-04-06 06:47:51