springboot+dubbo项目运行主jar时找不到rpc的bean
- resources目录下有conf目录,里面放置dubbo.xml和所要调用dubbo服务的其他dubbo.xml
- 打包时如果把这个conf打进jar中,项目可以运行,如果把conf不打进jar,linux启动jar时会报错
APPLICATION FAILED TO START
Description:
A component required a bean named ‘xxxxxxxxxxxxxxxxxxxRpc’ that could not be found.
Action:
Consider defining a bean named ‘xxxxxxxxxxxxxxxxxxxRpc’ in your configuration.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Properties;
// 不用默认配置的数据源,自己配置
@SpringBootApplication(scanBasePackages = “com.pakege”,
exclude = {DataSourceAutoConfiguration.class, FlywayAutoConfiguration.class})
@EnableAspectJAutoProxy
@ServletComponentScan
@ImportResource(locations = {“classpath*:conf/*.xml”})
public class PybbsApplication {
public static void main(String[] args) {
SpringApplication.run(PybbsApplication.class, args);
}
分析:一般这种问题要么是没加载到配置文件,要么是配置文件里面配置路径不对
不知道为什么我的项目把dubbo配置文件不打在jar里面就找不到,可能是哪里写的有问题;
解决办法:
因为项目不会去加载jar外面的配置文件,在dubbo.xml配置<dubbo:registry address=“zookeeper://” />直接去注册中心找就行了,就不用再其他的dubbo.xml配置url
项目是从GitHub上down下来的,所以在对接其他项目的时候会有很多问题