发表于: 2021-04-18 23:24:28

2 1247


今天完成的事情:

了解springRMI运行过程


完成切换Server


继续解决之前的报错


明天计划的事情:

上传服务器运行



遇到的问题:

一堆小问题:

1.错误: 找不到或无法加载主类 com.kbk.domain.ServerDo

2.IDEA创建  iml文件,

3.maven项目打包时生成dependency-reduced-pom.xml

4.找不到maven-compiler-plugin 依赖,加上版本号就可以了  <version>3.8.1</version>

.......



收获:



springRMI
访问的过程:在spring中,客户端实际访问的由RmiProxyFactoryBean所生成的代理对象,是由这个代理对象去访问实际的类。
springRMI解决的问题:
1.原有的JAVARMI需要写很多样板代码,就像之前JDBC连接MYSQL一样。springRMI解决了这一个问题

2.原有的JAVARMI需要抛出很多RemoteException异常,这些都可以通过spring配置文件解决


private Logger logger= LoggerFactory.getLogger(RMIServiceChoice.class);
UserService userService=null;

public UserService getService(){

//int count=new Random().nextInt(2);
   int count = 0;
   if(count == 0){
try{
logger.info("尝试获取serverA的服务");
           userService=getServiceA();
           logger.info("已经获取serverA的服务");

       }catch (Exception e){
logger.error("服务A挂掉了,报错信息" + e.getMessage());
           e.printStackTrace();
           try {
logger.info("serverA的服务获取失败,获取serviceB的服务");
               logger.info("尝试获取serverB的服务");
               userService=getServiceB();
               logger.info("已经获取serverB的服务");
           }catch (Exception e1){
logger.error("服务全部挂掉了,报错信息" + e1.getMessage());
               e1.printStackTrace();
           }
}
}else if(count == 1){
try{
logger.info("尝试获取serverB的服务");
           userService=getServiceB();
           logger.info("已经获取serverB的服务");
       }catch (Exception e){
logger.error("服务B挂掉了,报错信息" + e.getMessage());
           e.printStackTrace();
           try {
logger.info("serverB的服务获取失败,获取serviceA的服务");
               logger.info("尝试获取serverA的服务");
               userService=getServiceA();
               logger.info("已经获取serverA的服务");
           }catch (Exception e1){
logger.error("服务全部挂掉了,报错信息" + e1.getMessage());
               e1.printStackTrace();
           }
}
}
return userService;
}
private UserService getServiceA(){
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
   return (UserService) applicationContext.getBean("UserServiceA");
}
private UserService getServiceB(){
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
   return (UserService) applicationContext.getBean("UserServiceB");
}


注释这个发现,Service根本没启动服务,启动服务发生报错

:org.springframework.beans.factory.BeanCreationException异常的解决办法

 


然后单独启动ServerDo,发生报错:



2021-04-19 11:10:15 CST ERROR com.kbk.domain.ServerDo31main - 报错信息Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\JAVASourceCode\SpringRMI-Task8\ServiceA\target\classes\com\kbk\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-mybatis.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;



org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\JAVASourceCode\SpringRMI-Task8\ServiceA\target\classes\com\kbk\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-mybatis.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)





返回列表 返回列表
评论

    分享到