aused by: java.lang.IllegalArgumentException: More than one fragment with the name [spring_web] was

报错More than one fragment with the name [spring_web] was found. This is not legal …

部分错误:

 Caused by: java.lang.IllegalArgumentException: More than one fragment with the name [spring_web] was found. This is not legal with relative ordering.
 See section 8.2.2 2c of the Servlet specification for details. Consider using absolute ordering.
                at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2257)
                at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2215)
                at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1134)
                at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:775)
                at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
                at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5048)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                ... 26 more

解决办法就是:

在web.xml加一个标签:<absolute-ordering />
在这里插入图片描述

### Java中关于`Property 'sqlSessionFactory'或'sqlSessionTemplate'是必需的` `IllegalArgumentException`异常解决方案 #### 一、确认配置文件中的SQL会话工厂设置 确保项目中已正确定义了`SqlSessionFactory` Bean 或者 `SqlSessionTemplate` Bean。如果使用的是XML配置方式,则需检查相应的bean定义是否正确无误[^1]。 ```xml <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 数据源 --> </bean> ``` 对于基于注解的方式,应该有如下形式: ```java @Configuration public class MyBatisConfig { @Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); // 配置数据源和其他属性... return sessionFactory.getObject(); } } ``` #### 二、验证依赖项版本兼容性 仔细核对项目的POM文件或其他构建工具配置文件里的MyBatis及其扩展库版本号,保证它们之间相互匹配并能正常工作在一起[^3]。 例如,在Maven环境中应包含类似下面这样的条目: ```xml <!-- mybatis核心库 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- spring-mybatis适配器 --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis.spring.boot.starter.version}</version> </dependency> ``` 请注意替换`${}`内的占位符为实际使用的稳定版次。 #### 三、移除不必要的排除规则 当采用Spring Boot时,默认情况下已经包含了必要的自动化配置组件;除非确实有必要自定义某些行为,否则不建议随意修改默认的行为模式。特别是涉及到数据库连接池等基础设施级别的改动更应当谨慎对待[^4]。 因此,可以尝试恢复原始状态下的@SpringBootApplication标注而不再额外指定exclude参数: ```java @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 通过以上措施通常能够有效解决因缺少必要资源而导致抛出此类型的运行期异常的情况。当然具体问题还需结合实际情况进一步排查分析才能得出最合适的处理办法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小倪长头发啦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值