Category Archives: JAVA

[IDEA] Maven Run Project Error: Diamond operator is not supported in – source 1.5″

Error running project on idea “The diamond operator is not supported in – source 1.5”, because lambda expressions, a new feature in Java 8, have been used in the project. Of course, the syntax of 1.5 is not supported.

Solution:

1. Ensure that the bytecode compilation version in Java compiler in setting in idea is 8

2. Modify the language level of the module in the project structure to 8.

3. Check the pom.xml file of Maven project to see if the following attributes are added.

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
</properties>

[Solved] Factory method ‘jdbcDialect‘ threw exception; nested exception is org.springframework.data.jdbc.repo

When I use spring boot starter JDBC, there is a problem after configuring the data source. It prompts me to provide a dialect object for the data source.

Because I use the domestic Damon database, spring does not provide the corresponding dialog, and I am too lazy to write. The solution is very simple. Replace spring boot starter JDBC with Tomcat JDBC
my data source configuration is as follows:

Tomcat JDBC dependency:

Application.yaml

Successfully resolved:

But later, I found that it reported a password error. It turned out that my password was wrong. I needed to add double quotation marks to the password to run normally. However, I saw that others could run without adding them. Forgive me for my little white didn’t understand

Later, the pom.xml file was changed

Application.yaml: the password is enclosed in double quotation marks

Test run succeeded:

JAVA: scanner Read File encoding Error noSuchElementException

I need to demonstrate to customers locally importing data from postgresql into elasticsearch. I wrote a program read3.java in idea. There is no problem reading the file content with scanner.

But this read3.java is only used to convert the json file exported by the table into a valid json file that can be imported into es, and does not add the dependency that needs to be downloaded, but I have to do it in the idea every time I run it.

So I directly found the target path of read3.java and copied it to the desktop.

Compile a .class file with javac directly on the desktop and then start running.

Every time there is an error, that is

Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)

……

Then I reopened the notepad and created an abc.json file, saved the encoding format as “utf-8”, and then used read3 to read the file, and the read out was garbled.

So I thought that there is a problem with the encoding of the characters read by the scanner. When creating the scanner, specify the encoding, that is, Scanner sc=new Scanner(new FIle(“xxx”),”utf-8″));

Then use notepad++ to open the file that needs to be read, and find that the file encoding is utf-8 bom, so I converted the encoding format to utf-8 and re-run. The problem is solved.

[Solved] java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUni

You will see this on the Internet: the solution is to remove the JavaEE package from MyEclipse, create your own user libraries, add the jsf-api.jar jsf-impl.jar jstl-1.2.jar package in JavaEE, and then add the servlet-api.jar in Tomcat. In fact, the javaee.jar in JavaEE is replaced with the servlet-api.jar in Tomcat. This problem is solved.

You can also see this solution:

 <dependency>
			<groupId>tk.mybatis</groupId>
			<artifactId>mapper-spring-boot-starter</artifactId>
			<version>1.1.1</version>
			<exclusions>
				<exclusion>
					<groupId>javax.persistence</groupId>
					<artifactId>persistence-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

You can also see this solution:

<dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>

You can also see this solution:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

There is also this solution:

<dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>

Try it all

[Solved] Springboot test class injection bean is null Error: java.lang.NullPointerException…

When the springboot test class injects a NullPointerException object:

Normally, the test class add @springboottest can be tested normally

However, the value of classes in @ springboottest (classes = bootapplication. Class) can inject properties normally only after the class is started. That is, bootapplication is the springboot startup class

@RunWith(SpringRunner.class)

@SpringBootTest(classes = GrouptwoApplication.class)

[Solved] Java compilation error: unmapped character encoding GBK

Today, a helloworld.java source file is created by using the Echo instruction of the windows command line. The following errors are reported when compiling into a bytecode file:

Cause and solution: when javac compiles the source file, it needs to decode the source file. By default, the character encoding of the operating system is used for decoding. The simplified version of win11 uses GBK, so pay attention to whether GBK is used when encoding the source file. If there is only English, the encoding method of the source file is only compatible with ASCII code. Or you can change the character encoding during decoding through the command parameters of javac.

[Solved] layui url: rendering data error (thymeleaf)

1. Error information

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/user/user-list.html]")
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) ~[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.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) [spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) [spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) [tomcat-embed-core-9.0.39.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) [tomcat-embed-core-9.0.39.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_241]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.39.jar:9.0.39]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_241]
Caused by: org.attoparser.ParseException: Could not parse as expression: "
                {type: "checkbox", width: 50},
                {field: 'username', width: 80, title: '用户名'},
                {field: 'number', width: 80, title: '账号', sort: true},
                {field: 'phone', width: 80, title: '手机号码'},
                {field: 'email', title: '邮箱', minWidth: 150},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            " (template: "user/user-list" - line 87, col 21)
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    ... 48 common frames omitted

Solution: add th: inline = “None” in the script tag

<script th:inline="none">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/tuserList',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'username', width: 80, title: '用户名'},
                {field: 'number', width: 80, title: '账号', sort: true},
                {field: 'phone', width: 80, title: '手机号码'},
                {field: 'email', title: '邮箱', minWidth: 150},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],

[Solved] Springboot startup error: org.springframework.beans.factory.unsatisfieddependenceexception…

Error Messages:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexController': Unsatisfied dependency expressed through field 'indexService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexServiceImpl': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [I:\LX\aci_parent\service\service_acl\target\classes\com\lianxi\aclservice\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [I:\LX\aci_parent\service\service_acl\target\classes\com\lianxi\aclservice\mapper\xml\PermissionMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [I:\LX\aci_parent\service\service_acl\target\classes\com\lianxi\aclservice\mapper\xml\PermissionMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.atguigu.aclservice.entity.Permission'.  Cause: java.lang.ClassNotFoundException: Cannot find class: com.atguigu.aclservice.entity.Permission

There are various cases of this error, one is that your mysql configuration is wrong, one is that your SQL statement or entity class is not correct. Another is that the xml mapping path is not correct.

[Solved] java.lang.illegalstateexception: unable to forward after submitting the response

The root cause of this problem is this line of code:

The solution is to delete the line of super.

This line of code is simply understood as: the default implementation of the dopost method of the httpservlet returns the HTTP 405 status code.

The doget or dopost method of the parent httpservlet overrides the method you override. The default implementation of the doget or dopost method of the parent httpservlet returns an HTTP error with a status code of 405, indicating that the request method for the specified resource is not allowed.