linux上启动tomcat报错:Failed to read schema document 'http://www.springframework.org/schema/data/mongo/sp...

Spring XSD文件加载机制
本文解析了Spring框架如何加载xsd文件的过程。当Spring尝试从本地查找xsd文件未果时,它会转而从网络下载。这通常发生在声明的xsd版本高于依赖的Spring jar版本时。文章还解释了spring.schemas文件的作用及其可能导致的问题。

本文原文连接: http://blog.youkuaiyun.com/bluishglc/article/details/7596118 ,转载请注明出处!

spring在加载xsd文件时总是先试图在本地查找xsd文件(spring的jar包中已经包含了所有版本的xsd文件),如果没有找到,才会转向去URL指定的路径下载。

问题就是为什么spring在本地没有找到需要的文件,不得不转向网站下载。关于这个问题,其实也非常简单。在很多spring的jar包里,在META-INF目录下都有一个spring.schemas,这是一个property文件,其内容类似于下面

  

 

 

实际上,这个文件就是spring关于xsd文件在本地存放路径的映射,spring就是通过这个文件在本地(也就是spring的jar里)查找xsd文件的。那么,查找不到的原因排除URL输入有误之外,可能就是声明的xsd文件版本在本地不存在。一般来说,新版本的spring jar包会将过去所有版本(应该是自2.0以后)的xsd打包,并在spring.schemas文件中加入了对应项,出现问题的情况往往是声明使用了一个高版本的xsd文件,如3.0,但依赖的spring的jar包却是2.5之前的版本,由于2.5版本自然不可能包含3.0的xsd文件,此时就会导致spring去站点下载目标xsd文件,如遇断网或是目标站点不可用,上述问题就发生了

 

转载于:https://www.cnblogs.com/xiaoliangup/p/9582278.html

现有一个springboot项目,配置了多个数据源,在选择下面Cassandra数据库的service启动服务时,报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userLogInOutController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'CassandraUserService' defined in file [F:\basic-spring-boot\target\classes\com\tplink\nbu\demo\basicspringboot\service\impl\CassandraUserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 2 nodes, use getAllErrors() for more): Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=2e3966fc): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)], Node(endPoint=localhost/0:0:0:0:0:0:0:1:9042, hostId=null, hashCode=2084e1bf): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)] 原因是什么? 配置文件如下所示 spring: profiles: active: cassandra grpc: server: port: 9091 system: max-user-limit: 10 management: endpoints: web: exposure: include: metrics # ==================== MySQL 配置 ==================== --- spring: config: activate: on-profile: mysql datasource: url: jdbc:mysql://localhost:3306/springbootdemo?useSSL=false&serverTimezone=UTC&characterEncoding=utf8 username: root password: 159357 driver-class-name: com.mysql.cj.jdbc.Driver jpa: show-sql: true hibernate: ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect format_sql: true jdbc: lob: non_contextual_creation: true autoconfigure: exclude: - org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration - org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration - org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration # ==================== Cassandra 配置 ==================== --- spring: config: activate: on-profile: cassandra # 激活cassandra profile时使用此配置 data: cassandra: keyspace-name: my_database local-datacenter: datacenter1 contact-points: localhost port: 9042 # 默认Cassandra端口 compression: none schema-action: CREATE_IF_NOT_EXISTS connection: connect-timeout: 10s init-query-timeout: 10s autoconfigure: exclude: - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration - org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration # ==================== MongoDB 配置 ==================== --- spring: config: activate: on-profile: mongodb data: mongodb: host: localhost port: 27017 database: my_database autoconfigure: exclude: - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration - org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration - org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration
最新发布
09-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值