1 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 | -Dfile | 指定编译文件存储路径 |
2 | encoding=UTF-8 | 指定编码utf-8 |
3 | /tmp/cp_4a4xlx9v2chcgelfqeipya6kr.jar | 文件输出路径及文件 |
4 | basic.datatype.test.OutputTest | java文件路径 |
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" />
- 方案
将&修改为:&
<property name="url" value="jdbc:mysql://localhost:3306/db_monkey_run?useUnicode=true&characterEncoding=UTF-8&useSSL=false&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