Tag Archives: JDK1.8

IDEA Import Servlet Package Error [How to Solve]

When we use idea to import packages related to servlets, we sometimes encounter errors, which leads to the problem that servlets cannot recognize. In fact, the reason for the problem is very simple, that is, we can’t find packages related to servlets in JDK

Solution:
1. Find the installation directory of Tomcat, here is C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib (Note: not everyone’s directory is this, need to be based on the actual situation of your computer’s installation directory), find the Servlet-api.jar This file, copy it

2. then go to the JDK installation directory: C:\Program Files\Java\jdk1.8.0_241\jre\lib\ext, find the ext folder, and then copy the Servlet-api.jar file just copied to this folder

3. Back to the idea, the problem is solved, if the idea is still reporting errors, restart the idea refresh

[Solved] Failed to start bean ‘eurekaAutoServiceRegistration‘; nested exception is java.lang.NullPointerExce

When using spring-cloud-starter-netflix-eureka-client, the following exception was encountered when starting the project. Failed to start bean ‘eurekaAutoServiceRegistration’; nested exception is java.lang.NullPointerExce

org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at com.shanba.SbnsyhManageApplication.main(SbnsyhManageApplication.java:12) [classes/:na]
Caused by: java.lang.NullPointerException: null
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:73) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	... 14 common frames omitted

Reason: spring cloud’s jar package is introduced in POM in sequence

Wrong reference

<!--thymeleaf Template engine configuration-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Web依赖-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Normal reference

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--thymeleaf Template engine configuration-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Web-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

JAVA lambda Syntax error on tokens, Expression expected instead

Lambda is a new feature after JDK1.8, and I note that there was a problem when I first used lambda
The author USES versions: MyEclipse8.5, JDK1.8.0, and IDEA2018.2.5
When I run the following lambda code on MyEclipse, an error message appears:

package com.text;

public class Lambda {
	public static void main(String[] args) {
		Lambda lambda = new Lambda();
		lambda.oldRunable();
		lambda.runable();
	}

	public void oldRunable() {
		new Thread(new Runnable() {
			public void run() {
				System.out.println("The old runable now is using!");
			}
		}).start();
	}
	
	public void runable() {
        new Thread(()->System.out.println("It's a lambda function!")).start();
    }
}

Code line 19 reports an error:

Multiple markers at this line
    - Syntax error on tokens, Expression expected instead
    - Syntax error on token(s), misplaced construct (s)

After a search on the Internet, there was no explanation for this anomaly, and then I decided to run IDEA for a try. It turned out that the same code IDEA was not wrong, so this is for record
The author estimates that it may be because the version of MyEclipse8.5 is too low, but the author has not changed the version of MyEclipse, and I will try it again in the future. You are welcome to comment on the upgraded version, thank you