在web环境中,一般serviceImpl中的dao之类的数据库连接都由容器启动的时候创建好了,不会报错。但是在main中,没有这个环境,所以需要获取环境:

ApplicationContext ctx = new FileSystemXmlApplicationContext("src/applicationContext.xml");
        PianoServiceImpl pianoService = (PianoServiceImpl) ctx.getBean("pianoServiceImpl");
//然后再调用方法
        return pianoService.getPriceByBrand(brand);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-12-20
  • 2022-12-23
  • 2021-04-07
猜你喜欢
  • 2022-12-23
  • 2021-12-22
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
相关资源
相似解决方案