中间件 ZK分布式专题与Dubbo微服务入门 8-7 使用main主线程启动dubbo服务

0    课程地址

https://coding.imooc.com/lesson/201.html#mid=12745

 

1    重点关注

1.1    本节内容

使用main主线程启动dubbo服务

 

1.2    未解决问题

本节service没有依赖成功api,

经查询可能是sts版本问题,没有重新加载的选项(mavenrepositories没有rebuild index选项,并且仓库不可修改在c盘,后边有时间重新换个版本的试试)

 

 

 

 

2    课程内容

 

 

 

3    Coding

3.1    使用tomcat启动dubbo服务

  • 主要改造点:

涉及父项目,common项目,service和api项目共4个,

涉及

a  将启动的main方法写到service子项目,main方法加载主配置文件

b  主配置文件将所有配置文件聚合到一起

 

 

  • a  将启动的main方法写到service子项目,main方法加载主配置文件

ItemApplication

package com.imooc.item.starter;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ItemApplication {

    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] {"classpath:spring/spring-context.xml"});
        context.start();
        // press any key to exit
        System.in.read();
    }

}

 

 

  • b  主配置文件将所有配置文件聚合到一起

spring-context.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-4.2.xsd">
        
    <import resource="classpath:spring/applicationContext-dao.xml"/>
    <import resource="classpath:spring/applicationContext-dubbo-provider.xml"/>
    <import resource="classpath:spring/applicationContext-service.xml"/>
    <import resource="classpath:spring/applicationContext-transaction.xml"/>
    
</beans>

 

  • c  启动main方法即可














發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章