Java问题系列2

1 visual code编译java程序

在这里插入图片描述

图1.0 visual code运行java

visual code运行java程序,默认将打包jar文件复制到目录:/tmp;
运行Run:
/usr/java/jdk1.8.0_191/bin/java -Dfile.encoding=UTF-8 -cp /tmp/cp_4a4xlx9v2chcgelfqeipya6kr.jar basic.datatype.test.OutputTest
在这里插入图片描述

图1.2 visual code控制台

其中,

序号命令描述
1-Dfile指定编译文件存储路径
2encoding=UTF-8指定编码utf-8
3/tmp/cp_4a4xlx9v2chcgelfqeipya6kr.jar文件输出路径及文件
4basic.datatype.test.OutputTestjava文件路径

2 org.apache.jasper.servlet.TldScanner.scanJars

  • 方案:
    修改tomcat配置文件:loggging.properties
  • 添加:
org.apache.jasper.compiler.TldLocationsCache.level = FINE

3 xml配置文件加载错误

  • 错误提示
    (1) Context initialization failed java.lang.NoSuchMethodError
    (2) ERROR org.springframework.web.context.ContextLoader
    (3) Context initialization failed java.lang.NoSuchMethodError
    (4) Exception sending context initialized event to listener instance of class
  • 原因
    web.xml文件中,参数<context-param>配置错误,多文件配置形式错误:classpath:one.xml,classpath:two.xml
<context-param>
  		<!-- 加载src目录下的applicationContext.xml文件 -->
  		<param-name>contextConfigLocation</param-name>
  		<param-value>
			  classpath:config/applicationContext.xml,
			  classpath:config/kafkaBeans.xml
  		</param-value>
	  </context-param>
  • 解决
    多个文件,classpath加星号*,classpath*:one.xml,classpath*:two.xml
<context-param>
  		<!-- 加载src目录下的applicationContext.xml文件 -->
  		<param-name>contextConfigLocation</param-name>
  		<param-value>
			  classpath*:config/applicationContext.xml,
			  classpath*:config/kafkaBeans.xml
  		</param-value>
	  </context-param>

4 ssm框架数据库mysql搜索报错

(1) java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L
(2) java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.get

  • 原因
    mybatis版本问题,1.3.4及1.3.0一下版本报错.

  • 解决
    修改mybatis版本

<dependency>
	<groupId>org.mybatis</groupId>
	<artifactId>mybatis-spring</artifactId>
	<version>1.3.0</version>
</dependency>
<!-- mybatis实体类自动生成插件 -->
<dependency>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-core</artifactId>
	<version>1.3.0</version>
</dependency>

5 maven打包war名称修改

修改pom.xml文件中finalname名称

  • pom.xml
<build>
    <finalName>ssmPureBackendMultiDbSource</finalName>
    <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <!--编译src的Mapper文件-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
  </build>

6 类型转换错误

(1) Failed to convert property value of type ‘java.util.ArrayList’ to required type ‘org.springframework.core.io.Resource’
(2) Cannot convert value of type ‘java.util.ArrayList’ to required type ‘org.springframework.core.io.Resource’
(3) org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in URL
name使用mapperLocations,value使用xml文件:classpath:com/datasource/mybatis/*.xml

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dynamicDataSource" />  
		<!-- configLocation的属性值为MyBatis的核心配置文件 -->
		<!-- classpath: target/classes -->
		<!-- <property name="configLocation"> -->
		<property name="mapperLocations">
			<list>
				<value>classpath:com/datasource/mybatis/*.xml</value>
			</list>
		</property>
	</bean>

7 Visual Code修改编译器1.5为1.8

Java项目文件:.setting/org.eclipse.jdt.core.prefs

  • 原始文件
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
  • 问题
    使用1.5编译器,无法使用@Override,导致:The method must override a superclass method
  • 方案
    将1.5编译器修改为1.8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

8 集成Mybatis问题

  • 异常
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 120; 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾。
  • 原因
    配置文件中使用了&,不能识别。
<property name="url" value="jdbc:mysql://localhost:3306/db_monkey_run?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai" />
  • 方案
    将&修改为:&amp;
<property name="url" value="jdbc:mysql://localhost:3306/db_monkey_run?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone=Asia/Shanghai" />

【参考文献】
[1]https://www.cnblogs.com/mrray1105/p/9229023.html
[2]https://www.cnblogs.com/lukelook/p/11071762.html
[3]https://blog.csdn.net/maoyuanming0806/article/details/77689170
[4]https://www.cnblogs.com/Hdaydayup/p/6629034.html
[5]https://blog.csdn.net/majian/article/details/106114648
[6]https://blog.csdn.net/qq542045215/article/details/45313507

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

天然玩家

坚持才能做到极致

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

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

打赏作者

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

抵扣说明:

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

余额充值