`
mizhao1984
  • 浏览: 88521 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

osgi中spring-DM的用法

阅读更多

准备工作:下载spring-DM以来的包,并以插件的形式导入到工程中

1.创建一个plug-in project:UserInterface用于接口编写

 

public interface UserInterface {
    public void addUserInfo(UserInfo userInfo);

}

 

public class UserInfo {
 private int id;
 private String username;
 private String password;

 public int getId() {
  return id;
 }

 public void setId(int id) {
  this.id = id;
 }

 public String getUsername() {
  return username;
 }

 public void setUsername(String username) {
  this.username = username;
 }

 public String getPassword() {
  return password;
 }

 public void setPassword(String password) {
  this.password = password;
 }

}

MANIFEST.MF中将方法所在的包导出

 

2.创建一个plug-in project:UserImpl用于接口实现编写

MANIFEST.MF中将1导出的包导入

public class UserImpl implements UserInterface{
 
 public static final Log log = LogFactory.getLog(UserImpl.class);

 @Override
 public void addUserInfo(UserInfo userInfo) {
  log.info("addUserInfo excu...");
 }

}

在META-INF下创建文件夹spring:

在spring文件夹下新建:

bean.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.xsd" default-autowire="byName">
      <bean id="userImpl" class="com.oohla.service.impl.UserImpl"></bean>
</beans>

services-public-cxf.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"
  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" default-autowire="byName">

    <osgi:service id="userInterface" ref="userImpl" interface="com.oohla.service.UserInterface"></osgi:service>
</beans>

 

3.创建一个plug-in project:Test用于测试接口

MANIFEST.MF中将1导出的包导入

测试类:

public class Test {
 
 private UserInterface userInterface;

 public UserInterface getUserInterface() {
  return userInterface;
 }

 public void setUserInterface(UserInterface userInterface) {
  this.userInterface = userInterface;
 }

 public void setUser(UserInterface userInterface) {
  this.userInterface = userInterface;
 }
 
 public void addUser(){
  UserInfo userInfo = new UserInfo();
  userInfo.setId(1);
  userInfo.setUsername("mz");
  userInfo.setPassword("123");
  System.out.println("Test addUser...");
  userInterface.addUserInfo(userInfo);
 }

}

在META-INF下创建文件夹spring:

在spring文件夹下新建:

beans.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.xsd" default-autowire="byName">
      <!-- 启动通话监听任务 -->
      <bean id="test" class="com.oohla.test.Test" init-method="addUser">
          <property name="userInterface" ref="userInterface"></property>
      </bean>
</beans>

services-reference-cxf.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"
  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" default-autowire="byName">
    <osgi:reference id="userInterface" interface="com.oohla.service.UserInterface"></osgi:reference>                   
</beans>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics