让所有这些都发挥作用:战争、OSGI、SpringBeans、Maven
尝试在Fuse Servicemix(版本4.3.1)中使用bean文件部署war。我用maven来建立我的战争。我好像没法让它工作。谁能提供一个网站,可以告诉我如何做到这一点 这个网站告诉我在web.xml文件中放什么,但没有解释其余的内容 在19天的过程中,我尝试了几种解决方案和方法。每个人似乎给这只猫剥皮的方式都不一样,但没有一只适合我 肥胖战争(已解决): 见下面的答案让所有这些都发挥作用:战争、OSGI、SpringBeans、Maven,maven,war,fuseesb,jbossfuse,Maven,War,Fuseesb,Jbossfuse,尝试在Fuse Servicemix(版本4.3.1)中使用bean文件部署war。我用maven来建立我的战争。我好像没法让它工作。谁能提供一个网站,可以告诉我如何做到这一点 这个网站告诉我在web.xml文件中放什么,但没有解释其余的内容 在19天的过程中,我尝试了几种解决方案和方法。每个人似乎给这只猫剥皮的方式都不一样,但没有一只适合我 肥胖战争(已解决): 见下面的答案 骨瘦如柴的战争: 在osgi中似乎不可能。需要手动导入太多的包。 这种联系似乎解决了这个问题,但似乎有很多令人讨厌
骨瘦如柴的战争: 在osgi中似乎不可能。需要手动导入太多的包。 这种联系似乎解决了这个问题,但似乎有很多令人讨厌的副作用
您需要将Spring OSGi ContextLoaderListener添加到web.xml中,否则它将无法工作。您还需要Spring DM 1.2.1的依赖项。 请看一看,尤其是其中的web.xml。这是一个关于如何在Karaf/Fuse ServiceMix中使用Spring的工作示例 我想我给你指错样品了。您不需要使用以下命令 上下文类
org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext
脂肪战争解决方案 这是对我有效的最低可行解决方案。我试着删除一些东西,但它很快就坏了,甚至没有发布错误消息
目录结构:
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>
阿希姆。我在上面提供的链接告诉我要包含ContextLoaderListener,所以我在这里很好。我以你为例,试了一下。我删除了所有jsp内容,只使用了一个简单的web.xml和ContextLoaderListener以及一个welcome index.html页面。捆绑加载正常,没有错误。但是我的bean中的print语句从不激发。将代码添加到原始帖子。阿希姆,这绝对是在跳过我的bean文件。我远程调试并在println中添加了换行符。它从未执行过。我更正了上下文类,很抱歉样本错误。伙计,你的设置有多旧,Pax Web现在在2.1版中可用,3.0.0版很快就要发布了。也许你的设置太简单了?好吧,我在PaxWeb上添加了一个SpringOSGi示例。请看相应的测试
<?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 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>
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; }
}