目录

 

1. 利用下面方法启动spring boot 项目是系统参数不生效

2. org.drools.template.parser.DecisionTableParseException: Failed to open Excel stream, please check that the content is xls97 format.

3. java.lang.NoClassDefFoundError: Lcom/netflix/config/CachedDynamicIntProperty;

4.  Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

5. server.context-path 不起作用了

6. 同时使用ORM技术(Hibernate、JPA、JDO)和JDBC技术(Spring JDBC、iBatis)时, TransationManager怎么配

7.  Exception processing template "xlsx***": Error resolving template [***], template might not exist

8. The dependencies of some of the beans in the application context form a cycle

9. Log4j2 error- ERROR StatusLogger Unrecognized format specifier

10. Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.SAXParserFactory: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found

11. 类找不到的问题

12. Jar 包有问题


版本

LibraryCurrentUpgraded
Spring Boot1.5.19.RELEASE2.3.2.RELEASE
Spring Framework4.3.22.RELEASE5.2.8.RELEASE

1. 利用下面方法启动spring boot 项目是系统参数不生效

[02:15:30][Step 2/2] The system property 'syst1' must be defined

相关命令

mvn spring-boot:run -Dsys1=system1, -Dsys2=system2

解决方法:把系统参数现在-Dspring-boot.run.jvmArgument=“....”里面

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dsys1=system1, -Dsys2=system2"

2. org.drools.template.parser.DecisionTableParseException: Failed to open Excel stream, please check that the content is xls97 format.

错误信息如下:

Caused by: java.util.zip.ZipException: invalid stored block lengths
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164) ~[?:1.8.0_51]
at java.util.zip.ZipInputStream.read(ZipInputStream.java:194) ~[?:1.8.0_51]
at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:168) ~[poi-ooxml-3.13.jar:3.13]
at java.io.FilterInputStream.read(FilterInputStream.java:107) ~[?:1.8.0_51]
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.<init>(ZipInputStreamZipEntrySource.java:130) ~[poi-ooxml-3.13.jar:3.13]
......
at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:64) ~[drools-compiler-6.3.0.Final.jar:6.3.0.Final]
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:229) ~[drools-compiler-6.3.0.Final.jar:6.3.0.Final]
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:197) ~[drools-compiler-6.3.0.Final.jar:6.3.0.Final]
。。。。

Caused by: org.drools.template.parser.DecisionTableParseException: Failed to open Excel stream, please check that the content is xls97 format.

再Maven里加下面代码确保xlsx不用被Maven过滤。如果被Maven过滤的话好像它会改里面的东西。

  <resource>
    <directory>src/main/resources</directory>
    <filtering>false</filtering>
    <includes>
      <include>**/*.xlsx</include>
    </includes>
  </resource>

参考资料

Drools: Caused by: java.util.zip.ZipException: invalid stored block lengths – Wevodio

3. java.lang.NoClassDefFoundError: Lcom/netflix/config/CachedDynamicIntProperty;

解决方法:把Archaius-core 更新到0.7.6 version

4.  Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'redisMessageListenerContainer', defined in class path resource [org/springframework/boot/autoconfigure/session/RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration.class], could not be registered. A bean with that name has already been defined in com.example.RedisApplication and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

原因

spring boot 2.1 之后取消了覆盖Bean这一默认特性。原来默认是可以创建多个一样名字的Bean的。

参考资料

https://www.baeldung.com/spring-boot-bean-definition-override-exception

解决方法

加系统参数在application.properties

spring.main.allow-bean-definition-overriding=true

5. server.context-path 不起作用了

我配置的 server.context-path=/web

错误信息如下:

控制檯資訊

 但是log 里面看出,cootext path不生效

原因:spring boot2.0 之后。这个配置改名为server.servlet.context-path。

解决方法:改为server.servlet.context-path名字

#server.context-path=/web
server.servlet.context-path=/web

6. 同时使用ORM技术(Hibernate、JPA、JDO)和JDBC技术(Spring JDBC、iBatis)时, TransationManager怎么配

由于前者的会话(Session)是对后者连接(Connection)的封装,Spring会“足够智能地”在同一个事务线程让前者的会话封装后者的连接。所以,我们只要直接采用前者的事务管理器就可以了。表10-1给出了混合数据访问技术框架所对应的事务管理器。 

序    号混合数据访问技术框架事务管理器
1Hibernate+ Spring JDBC或iBatisorg.springframework.orm.hibernate5.HibernateTransactionManager
2JPA+Spring JDBC或iBatisorg.springframework.orm.jpa.JpaTransactionManager
3JDO+Spring JDBC或iBatisorg.springframework.orm.jdo.JdoTransactionManager

例如: 你的项目有配有HibernateTransactionManager,也有MyBatis的DataSourceTransactionManager。直接使用HibernateTransactionManager就可以了。

	@Bean
	public HibernateTransactionManager transactionManager(@Qualifier("hibernateSessionFactory")	SessionFactory sessionFactory)
 
	{
		HibernateTransactionManager htm = new HibernateTransactionManager();
		htm.setSessionFactory(sessionFactory);
		return htm;
	}
 
//	@Bean
//	public DataSourceTransactionManager transactionManager(@Autowired @Qualifier("dataSource") DataSource dataSource) {
//		DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);		
//		return transactionManager;
//	}

7.  Exception processing template "xlsx***": Error resolving template [***], template might not exist

错误信息如下:

[http-nio-8099-exec-1](org.thymeleaf.TemplateEngine:1136) - [THYMELEAF][http-nio-8099-exec-1] Exception processing template "userInformation": Error resolving template [userInformation], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [userInformation], template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37

相关代码:

@Controller
public class UserInformationController {
	@RequestMapping(method = RequestMethod.GET, value = "/userInformation")
	public ModelAndView getUserInformation(ModelMap  model) {
		List<User> users= ....
		model.addAttribute("users", users);
		return "userInformationReport"
	}
}

@Component("userInformationReport")
public class XlsxStreamingView extends AbstractXlsxStreamingView {
@Override
	protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
            List<User> users= = model.get("users");
    .....
     // POI related code.. 
		}
}

可以看到这里GetUserInformation方法的返回值是userInformationReport,原来是spring可以智能的调用下面那个类,但是现在不行了。

解决方法

import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.ModelMap;

@Controller
public class UserInformationController {

	@Autowired
	private XlsxStreamingView XlsxStreamingView;

	@RequestMapping(method = RequestMethod.GET, value = "/userInformation")
	public ModelAndView getUserInformation(ModelMap  model) {
		List<User> users= ....
		model.addAttribute("users", users);
        return new ModelAndView(XlsxStreamingView, model);
	}
}

8. The dependencies of some of the beans in the application context form a cycle


Description:

The dependencies of some of the beans in the application context form a cycle:

   userController (field private xxx.user.service.userWorkflowService xxx.user.controller.userController.userService)
      ↓
   userProcessorConfig
      ↓
   xxx.core.workflow.TestWorkflowConfiguration#0 (field private xxx.Test.service.TestDataService xxx.core.workflow.TestWorkflowConfiguration.pendingTestDataService)
┌─────┐
|  xxx.Test.TestConfiguration#0
↑     ↓
|  xxx.Test.util.ATestRuleConfiguration#0 (field private xxx.Test.TestConfiguration xxx.Test.util.ATestRuleConfiguration.TestConfiguration)
└─────┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

解决方法:

spring.main.allow-circular-references=true

9. Log4j2 error- ERROR StatusLogger Unrecognized format specifier

错误信息:

ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
ERROR StatusLogger Reconfiguration failed: No configuration found for '135fbaa4' at 'null' in 'null'

相关代码- pom.xml

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>				
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<finalName>your-component-name</finalName>
						</configuration>
					</execution>
				</executions>
			</plugin>

解决方法:

打包的时候去掉Log4j2Plugins.dat 文件。

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>				
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<finalName>your-component-name</finalName>
                             <filters>
								  	<filter>
                                	<artifact>*:*</artifact>
                                	<excludes>
	                                    <exclude>**/Log4j2Plugins.dat</exclude> 
                                	</excludes>
                            	</filter>
							</filters>
						</configuration>
					</execution>
				</executions>
			</plugin>

参考资料:

java - log4j2 ERROR StatusLogger Unrecognized conversion specifier - Stack Overflow

10. Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.SAXParserFactory: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found

错误信息:

Caused by: java.lang.RuntimeException: Provider for class javax.xml.parsers.SAXParserFactory cannot be created
        at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:308) ~[?:1.8.0_311]
        at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267) ~[?:1.8.0_311]
        at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127) ~[?:1.8.0_311]
        at org.appformer.maven.support.MinimalPomParser.parse(MinimalPomParser.java:53) ~[kie-soup-maven-support-7.35.0.Final.jar!/:7.35.0.Final]
        at org.appformer.maven.support.PomModel$DefaultPomModelGenerator.parse(PomModel.java:136) ~[kie-soup-maven-support-7.35.0.Final.jar!/:7.35.0.Final]
        at org.appformer.maven.support.PomModel$Parser.parse(PomModel.java:110) ~[kie-soup-maven-support-7.35.0.Final.jar!/:7.35.0.Final]
        at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildPomModel(KieBuilderImpl.java:590) ~[drools-compiler-7.35.0.Final.jar!/:7.35.0.Final]
        at org.drools.compiler.kie.builder.impl.KieBuilderImpl.init(KieBuilderImpl.java:154) ~[drools-compiler-7.35.0.Final.jar!/:7.35.0.Final]
        at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:220) ~[drools-compiler-7.35.0.Final.jar!/:7.35.0.Final]
        at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:194) ~[drools-compiler-7.35.0.Final.jar!/:7.35.0.Final]
...
Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.SAXParserFactory: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found
        at java.util.ServiceLoader.fail(ServiceLoader.java:239) ~[?:1.8.0_311]
        at java.util.ServiceLoader.access$300(ServiceLoader.java:185) ~[?:1.8.0_311]
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372) ~[?:1.8.0_311]
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) ~[?:1.8.0_311]
...

解决方法:

加xercesImpl包

		<dependency>
	 		<groupId>xerces</groupId>
  			<artifactId>xercesImpl</artifactId>
  			<version>2.12.0</version>
		</dependency>

11. 类找不到的问题

OldNew

 org.springframework.boot.context.embedded.

tomcat.TomcatEmbeddedServletContainerFactory

org.springframework.boot.web.embedded.

tomcat.TomcatServletWebServerFactory

org.springframework.boot.context.embedded

.tomcat.TomcatEmbeddedServletContainer

org.springframework.boot.web.embedded

.tomcat.TomcatWebServer

12. Jar 包有问题

ErrorSolution

Caused by: java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/

ServerPropertiesAutoConfiguration.class] cannot be opened

because it does not existatorg.springframework.core.io.

ClassPathResource.getInputStream

(ClassPathResource.java:180) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]

at org.springframework.core.type.classreading.SimpleMetadataReader.

getClassReader

(SimpleMetadataReader.java:55) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]

Spring-cloud-netflix-core

Caused by: java.lang.NoSuchMethodError: org.codehaus.stax2.ri.SingletonIterator.create(Ljava/lang/Object;

)Lorg/codehaus

/stax2/ri/SingletonIterator;
        at com.ctc.wstx.util.DataUtil.singletonIterator(DataUtil.java:41)

<dependency> 

 <groupId>org.codehaus.woodstox</groupId> 

  <artifactId>stax2-api</artifactId> 

  <version>4.2</version> 

</dependency>

The following method did not exist:

    javax.validation.spi.ConfigurationState.getParameterNameProvider()

Ljavax/validation/ParameterNameProvider;

The method's class, javax.validation.spi.ConfigurationState, is available from the following locations:

    jar:file:***/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar!/javax/validation/spi/ConfigurationState.class

    jar:file:**/repository/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar!/javax/validation/spi/ConfigurationState.class

The class hierarchy was loaded from the following locations:

移掉 validation-api/1.0.0.GA jar

What is Spring MVC: @Controllers & @RestControllers

相关系列博客

Hibernate升级到5.4.18.final的过程踩过的坑_keeppractice的博客-CSDN博客

Spring boot admin 升级到2.3.1 遇到的问题总结_keeppractice的博客-CSDN博客

[错误总结]升级spring-boot->2.6.2|hiberate->5.4.33.Final|spring cloud->2021.0.0 |spring admin->2.4.1

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐