关于SSH的SpringUtils.getBean("taxYearService")这个是用来做啥的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于SSH的SpringUtils.getBean("taxYearService")这个是用来做啥的相关的知识,希望对你有一定的参考价值。

求解这个SpringUtils.getBean("taxYearService")是用来干吗的,谁能给我解释下面的代码 public CommandVo saveCache(Command cmd, DynaActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception

// 取登录信息
Login login= BOUtil.getLoginInfo(request);
CommandVo vo = new CommandVo();
AppBo appBo=new AppBo();
String eattach=getParameter(form, request, "eattach");
String year=getParameter(form, request, "year");
String month=getParameter(form, request, "month");
TaxYearService taxYearService = (TaxYearService)SpringUtils.getBean("taxYearService");
//读取EXCEL
String filename="";
if(eattach!=null&&eattach!="")
List list =appBo.query("select * from eform_attach where id='"+eattach+"'");
if(list.size()>0)
filename=appUtil.getAttatchPath()+"/"+((HashMap)list.get(0)).get("SAVEFILE");


TaxYearCache taxYearCache =readXls(appBo,filename);
taxYearCache.setUsercode(login.id);
taxYearCache.setUsername(login.name);
taxYearCache.setDeptname(login.dept_name);
taxYearCache.setTime(Pub.GetFormatTime("yyyy-MM-dd"));
taxYearCache.setYear(year);
taxYearCache.setMonth(month);
taxYearService.createTaxYearCache(taxYearCache);
cmd.mapReturnForm.put("doKey", taxYearCache.getSno());
//读取EXCEL
//删除附件
File file = new File(filename);
if(file.exists())
file.delete();
appBo.runSQL("delete from eform_attach where id='"+eattach+"'");

//删除附件
log.info("eattach"+eattach);
request.setAttribute("message","成功读取"+(taxYearCache.getTaxYearInfoCaches().size()+1)+"条数据!");
cmd.forward="comfirmCache";
vo.setCommand(cmd);
return vo;

参考技术A 从字面意思上理解就是获取名为
taxYearService的bean本回答被提问者和网友采纳

在main方法中初始化spring环境,注入bean

public static void main(String[] args) {

    LOGGER.info("==启动APP日志队列程序==");
    SpringUtils.getBean(UserAppLogConsumerListener.class);
}

  一开始我是使用自定义的spring工具类的getBean方法进行初始化,但是存在问题:配置文件中用有引用UserAppLogConsumerListener这个bean,导致报错expected single matching bean but found 2

Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ‘com.cdd.rabbitmq.consume.listener.UserAppLogConsumerListener‘ available: expected single matching bean but found 2: userAppLogConsumerListener,userAppReceiver
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1039)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:339)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:334)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1107)
    at com.cdd.core.utils.SpringUtils.getBean(SpringUtils.java:28)
    at com.cdd.rabbitmq.consume.Main.main(Main.java:23)

  然后换了一种方式,直接根据配置文件加载ApplicationContext,成功

public static void main(String[] args) {

    LOGGER.info("==启动APP日志队列程序==");
//    SpringUtils.getBean(UserAppLogConsumerListener.class);
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
}

 

以上是关于关于SSH的SpringUtils.getBean("taxYearService")这个是用来做啥的的主要内容,如果未能解决你的问题,请参考以下文章

关于ssh密码忘记的处理

关于ssh免密互访

Linux关于ssh

关于ssh加密方式的理解

Linux关于ssh

关于ssh的问题