Tag Archives: java

Ubutnu’s idea input method candidate box can’t follow the cursor

Problem orientation
In fact, the specific issue of the official seven years ago (reference), but the more pit is that the official has not solved the problem. Simply put, a bug in the JRE running environment of IDEA causes the input method to be unable to locate the mouse position. Therefore, we need to modify the running code of JetBrainsRuntime to fix this problem.
The solution

Modify JetBrainsRuntime

    Download the modified JRE environment
https://pan.baidu.com/s/1S6cEKQS9w9dKqCrlO4QJwg
Extract code: 21MR

    Change the startup environment for IDEA

Change your own JRE directory

/home/ XXX /idea-2020.1/bin/idea.shhome/XXX /idea-2020.1/bin/idea.sh

port IDEA_JDK=/home/ XXX /idea-2020.1/java-11.0.7-jetbrain.>r> export IDEA_JDK=/home/ XXX /idea-2020.1/java-11.0.7-jetbrain
Appendix:
JetBrainsRuntime

Using global timing task cronutil in hutool tool class

The original address: https://www.cnblogs.com/xiaolong1996/p/9571645.html
Use the global timing task-cronutil in the Hutool utility class
Spring’s @Autowired annotation is used to inject the required service. When the add method in the service is called, the program raises a null pointer exception. In the thread, it is thread-safe, injection-resistant, and is resolved by the context object instance
 
package com.backstage.config;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/
* * * @ ProjectName:
* @ Package: com. Runs backstage. Config
* @ the ClassName: ApplicationContextProvider
* @ Description: get bean object tools
* @ Author: wangzhilong @ CreateDate
* :
* @version: 1.0
/
Author: * *
* ZhuShangJin Date:
* 2018/7/3/

* @ Component
public class ApplicationContextProvider implements ApplicationContextAware {

/* * *
the context object instance */
private static ApplicationContext ApplicationContext;
@Override
public void setApplicationContext(ApplicationContext) throws BeansException {
is.ApplicationContext = ApplicationContext;
}
/**
* @return
@return
* @return
publ>tatic ApplicationContext getApplicationContext() {
}

/* * * by the name for the Bean.

* * * @ @ param name
the return/

* public static Object getBean (String name) {
the return getApplicationContext().getBean(name);
}
/
* * * by class get beans.

* * @ param clazz
* @ param & lt; T>
* @ return/

* public static & lt; T> T getBean(Class< T> Clazz) {
return getApplicationContext () getBean (clazz);
}
/ * *
* by name, and the return of the Clazz specified Bean

* * @ param name
* @ param Clazz
* @ param & lt; T>
* @ return/

* public static & lt; T> T getBean(String name, Class< T> Clazz) {
return getApplicationContext().getBean(name, clazz);
}
 
Public TimingMonitoring () {//new injection need bean enclosing detailedDataService = ApplicationContextProvider. GetBean (detailedDataService. Class); }
}
 

Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project

Complete error message

Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project jurisdiction_controller: Could not start Tomcat


Start the Maven project wrong, use Tomcat embedded in it
The solution
The dependent use of servlets is introduced in the pom.xml file


Change after

add scope tags, and the values is provided (only role in the compilation and testing, and at the same time not pass)
The scope label specifies the range of values
compile
The default scope, which means that all Dependencies can be used throughout the lifecycle. Furthermore, these dependencies are passed to the projects on which they depend. Applies to all phases and will be released along with the project
provided
Similar to compile, but indicating that dependency is provided by JDKs or containers, such as Servlet APs and some Java EE APIs. This scope can only be used during compilation and testing and has no transitivity.
runtime
Dependency does not apply at compile time, but does apply at run and test times, such as JDBC drivers, for the run and test phases.
test
Indicates that dependency is applied at test time, not at run time. Used only during testing, to compile and run test code. Will not be released with the project.
system
Similar to Provided, but provided in the system as an external JAR, Maven does not look for it in a repository.

An error was reported when springboot connected to redis Servlet.service () for servlet [dispatcherServlet] in context with path [] threw e

Made a day, finally 11 o ‘clock more than solved, record once. SerializationException: Cannot SerializationException: Cannot SerializationException: Cannot SerializationException: Cannot SerializationException: Cannot SerializationException: Cannot SerializationException: Cannot SerializationException: Cannot SerializationException:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: com.wanghaixin.springboot.model.Student] with root cause
Solution:
NotSerializable is not serialized objects, object Article cannot be serialized therefore appeared this problem.
JavaBeans to cache must implement the Serializable interface, because Spring serializes objects before storing them in Redis
For this exception, just modify the corresponding JavaBean object, mine is Student

public class Student implements Serializable 

Spring boot project running error: Servlet.service () for servlet [dispatcherServlet] threw exception

spring boot
spring boot
spring boot
spring boot
spring boot
spring boot
Error output from console:

2020-06-29 12:25:44.780 ERROR 1968 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] threw exception

java.lang.StackOverflowError: null
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:583) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	

: The @Autowired annotation is not added to the implementation class in the Service layer. This will cause the implementation class to lack dependencies. An error will occur if the dependencies cannot be found after the project is started.
Original code:

   private EmployeeDao employeeDao;

Modified code after adding annotations:

 @Autowired
   private EmployeeDao employeeDao;

The problem is resolved by adding the @Autowired annotation.

Problems of accessing servlet display 404 on MyEclipse

Sometimes, when accessing a servlet in MyEclipse, a 404 page will appear. I won’t go into this if the web.xml is not configured properly or the URL is wrong, but I will talk about the situation where everything seems to be correct but I still can’t access it.
All you need to do is find the container where the servlet is running, in this case Tomcat, close it first, then locate the corresponding project in Tomcat, click ReDeploy, and then start Tomcat.

Possible causes and solutions of 404 problems in accessing servlet pages

Today I finished a function Want to direct input in the address bar servletA class and parameters to test the servlet code
an error 404. But I tested a new servletB class and it worked exactly the same way.
I was puzzled because both classes were servlets I created directly from Eclipse, and the web.xml was configured automatically. Even if the configuration is wrong it should be both wrong. Want to for a long time, suddenly think of you just created ServletA class, put the wrong to service pack, dragged her into the servlet found directly after the bag, but the web. The XML configuration path has been in the service package
as shown in figure
and the actual class names should be com. Student. Servlet. DeleteStudentServlet
for simple reason is:
I just begin to create the servlet misplacing to service the bag (actually should put the servlet bag), but to create the eclipse will help me get web. The XML class name is automatically configured (the name of the class is the route of the distribution of com. Student. Service. DeleteStudentServlet) and I treat the servlet to tow the servlet packages, web, XML is not modified, lead to the web. The path name of the class error in the XML. So when he visited the Servlet can’t find the correct path, to be an error 404.
so the Servlet error 404, must be sure to check the path name is correct, also want to check the web, XML configuration information is incorrect.
Summary: Make sure to go to web.xml to change the configuration if the package you created the Servlet contains changes.

404 error in browser accessing Servlet

The first Servlet program written with the MyEclipse tool — HelloWorld (refer to Section 4.1 of Java Web Programming). After the Web project is created, Tomcat is started through the MyEclipse development tool. See the Console window to output the server startup information as follows:

Then, when testing the program by typing the URL in the browser address bar, a 404 error occurs, as shown below:

My development environment is MyEclipse 2014+Tomcat 8.0. Previously, there were some new features in MyEclipse that did not support JDK 1.8. Later, I wondered if there was a version mismatch between development environments, so I tried to change Tomcat 8.0 to Tomcat 7.0.

Differences between Java and kotlin access modifiers

modifiers

Java

Kotlin

public

all kind of visible

all kind of visible (the default)

private

current class visible

current class visible

prote Cted

the current class, subclass, class is visible under the same package path

the current class, subclass visible

default

class visible (the default) under the same package path

no

internal

no

class is visible in the same module

Application of IntelliJ idea in Maven project pom.xml Add dependency


You can quickly add dependencies by using the shortcut Alt + Insert key at the location where you want to add them
The first feature allows you to search directly for the module name and then add it


The Dependency Template helps us generate the corresponding tags directly in the XML

We need to complete the information ourselves