Tag Archives: spring

Failed to read artifact descriptor for com.google.errorprone:javac:jar:9+181-r4173-1

Build failure occurs when Java Maven project is executed.

Full text of error report:

[ERROR] Failed to execute goal com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config (default-cli) on project spring-petclinic: 
Execution default-cli of goal com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config failed: Plugin com.microsoft.azure:azure-webapp-maven-plugin:1.12.0 or one of its dependencies could not be resolved: 
Failed to collect dependencies at com.microsoft.azure:azure-webapp-maven-plugin:jar:1.12.0 -> com.microsoft.azure:azure-maven-plugin-lib:jar:1.4.0 -> com.microsoft.azure:azure-tools-common:jar:0.9.0 -> com.google.errorprone:error_prone_core:jar:2.4.0 -> com.google.errorprone:error_prone_check_api:jar:2.4.0 -> com.google.errorprone:javac:jar:9+181-r4173-1: 
Failed to read artifact descriptor for com.google.errorprone:javac:jar:9+181-r4173-1: Could not transfer artifact com.google.errorprone:javac:pom:9+181-r4173-1 from/to aliyunmaven (https://maven.aliyun.com/repository/public): 
Access denied to: https://maven.aliyun.com/repository/public/com/google/errorprone/javac/9+181-r4173-1/javac-9+181-r4173-1.pom -> [Help 1]

resolvent:

reach   https://mvnrepository.com/   Find javac-9 + 181-r4173-1 in and download it   Error Prone Javac

Download in files   Javac-9 + 181-r4173-1.jar to local// Attempted to add dependency in pom.xml, invalid.

Then, execute the following command in CMD:

mvn install:install-file -DgroupId=com.google.errorprone -DartifactId=javac -Dversion=9+181-r4173-1 -Dpackaging=jar -Dfile=C:\Users\Administrator\Downloads\javac-9+181-r4173-1.jar

It can be installed normally.

reference:

https://www.freesion.com/article/74941283048/

Cannot resolve plugin org.springframework .boot:xxx

   During development, sometimes when you open a project to install a dependency, or create a new springboot project to install some dependencies, the following errors appear inexplicably:

First check whether there is a problem with the network. If the network is normal, 99% of the problems occur in the Maven configuration of the idea. Open it   settings   -& gt; Find the location of the screenshot below and modify the following two places:

Maven home path: the installation directory of Maven
user setttings file:   Maven installation directory – & gt; conf -> Setting.xml file path
local repository: This is a customized Maven local repository after downloading Maven. Mine is in the Maven installation directory.

   After these three settings are completed, click apply, OK and refresh.

 

[Solved] Rabbitmq injection failed, bean creation failed, error creating bean with name ‘rabbitconnectionfactory’‘

Error creating bean with name ‘spring.rabbitmq-org.springframework.boot.autoconfigure.amqp.RabbitProperties’

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rabbitConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration$RabbitConnectionFactoryCreator.class]: Unsatisfied dependency expressed through method 'rabbitConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.rabbitmq-org.springframework.boot.autoconfigure.amqp.RabbitProperties': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.amqp.RabbitProperties] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
	at com.ata.sms.simulator.Application.main(Application.java:14)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.rabbitmq-org.springframework.boot.autoconfigure.amqp.RabbitProperties': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.amqp.RabbitProperties] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1286)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
	... 20 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.amqp.RabbitProperties] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)
	... 33 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/amqp/rabbit/connection/AbstractConnectionFactory$AddressShuffleMode
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
	... 35 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.amqp.rabbit.connection.AbstractConnectionFactory$AddressShuffleMode
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 39 common frames omitted

Error reason: spring boot is used, but MQ. In spring boot is not used

Original dependence

<dependency>
    <groupId>org.springframework.amqp</groupId>
    <artifactId>spring-rabbit</artifactId>
    <version>2.2.5.RELEASE</version>
</dependency>

Amend to read

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

Mybatis plus configuration console prints complete SQL statement with parameters

Solution
if it is application.yml

#mybatis-plus configures the console to print full SQL statements with parameters
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

If it is application.properties, add:

#mybatis-plus configures the console to print full SQL statements with parameters
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

[Solved] java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed

Project scenario:

Spring boot project, user-defined filter, intercept requests and process business.


Problem Description:

When you start the project access interface, you call resp.sendRedirect () in the custom filter.


Cause analysis:

After the response has been submitted, the sendredirect() method cannot be called.

In fact, chain. Dofilter (req, resp) is executed; Cannot use sendredirect() of resp object after

So looking at the code, we find that:

...

  HttpServletRequest httpRequest = (HttpServletRequest) request;
  HttpServletResponse httpResponse = (HttpServletResponse) response;
  ....
  boolean flag = getStatus();
  if (flag) {
      ....
      chain.doFilter(request, response);
  }
  httpResponse.sendRedirect(“xxxx”);
...

if the judged flag is true, chain.dofilter (request, response) will be executed, and httpresponse.sendredirect (“XXXX”) </ font> will be executed after execution


Solution:

After chain. Dofilter (request, response), add return to end the current method.

...

  HttpServletRequest httpRequest = (HttpServletRequest) request;
  HttpServletResponse httpResponse = (HttpServletResponse) response;
  ....
  boolean flag = getStatus();
  if (flag) {
      ....
      chain.doFilter(request, response);
      return;
  }
  httpResponse.sendRedirect(“xxxx”);
...

[Solved] Java.util.linkedhashmap cannot be cast to entity class

Solve the problem of java.util.linkedhashmap cannot be cast to entity class

Background description

When learning about grain mall, openfeign is used for remote call, because an interface returns R < List<· Object>> Type of data, using list <Object> When receiving data, the java.util.linkedhashmap cannot be cast to XXX data conversion exception error occurs. It can be seen that the remote call will convert the data to be converted to LinkedHashMap, but it will not work to convert it to the desired data type.

Solution one

Use typereference in fastjson tool provided by Alibaba to transform.

We add SetData () and GetData () methods to R. when getting data, we use typereference class to indicate the data type. Then convert the map to the JSON string, and then convert the JSON string to the data type we want.

public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public R setData(Object data){
		put("data",data);
		return this;
	}

	//Reversal with fastjson
	public <T> T getData(TypeReference<T> typeReference){
		Object data = get("data");//Default is map type
		if(Objects.isNull(data)){
			return null;
		}
		String s = JSON.toJSONString(data);
		T t = JSON.parseObject("",typeReference);
		return t;
	}

Caller

        R r = wareFeignService.getSkusHasStock(skuIdList);//Remote calls
        TypeReference<List<SkuHasStockVo>> typeReference = new TypeReference<List<SkuHasStockVo>>() {
        };// Declare the internal class, specifying the type
        List<SkuHasStockVo> data = r.getData(typeReference);//get data for remote calls

reflection

This problem also occurred when using resttemplate remote call before. This problem was solved before, and the solution steps were not recorded. This time, the solution steps will be recorded to prevent the next step.

Supplementary solution 2

Recently, when reviewing the previous project code, I found a similar problem when using resttemplate remote call mentioned in my thinking. The solution at the time was this.

	import com.alibaba.fastjson.JSON;
	import com.alibaba.fastjson.JSONObject;
	
	//remote call, return the specified collection, but this collection can not be used directly, because he is a LinkedHashMap.
	List<InnerControl> remoteList = restTemplate.getForObject("url", List.class);
	remoteList = transToList(remoteList);// After the conversion, you will be able to use this collection normally.
	
	// Define a method to convert the LinkedHashMap type to the data type we want
	private List<InnerControl> transToList(List<InnerControl> list){
		String jsonStr = JSON.toJSONString(list);//still use the json conversion tool provided by alibaba.
		return JSONObject.parseArray(jsonStr, InnerControl.class);
	}

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communicat

Solution: when connecting to the database, change usessl = true to usessl = false. Of course, if usessl = true is not written, it is true by default.

Note: however, I don’t know why I did it. What’s more, the tutorial I read only uses true, and why I report an error. If a boss sees it, he hopes to answer it.

[Solved] Failed to resolve org.junit.platform:junit-platform-launcher:1.7.2

For springboot project, when using applicationtests to test, the following error will be prompted:

11:47 am  Error running ‘ShiroDemoApplicationTests.contextLoads’: Failed to resolve org.junit. platform:junit-platform-launcher :1.7.2

Reason: IntelliJ idea version and JUnit version do not match

solve:

1. Add the following dependencies to the pom.xml file of the project:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <scope>test</scope>
</dependency>

2. It is more troublesome to adjust the two versions to match. The first method is recommended.

[Solved] Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerExcepti

 

1、 Background description

Project architecture: spring boot (v2.0.0. Release) + mybatis plus (v3.1.1)

Today, I developed a new function on an old project (running normally). Before adding new functions, the project started and ran normally. As a result, after the development, the project couldn’t start and the background didn’t report any error information. The key is that I didn’t even have a log. For a moment, I couldn’t start it.

2、 Cause analysis

According to the situation analysis, the project can’t be started. Thinking that there must be a problem in starting, a try… Catch… Block is added to the line of starting the project in the starting class (that is, the following code plus).

SpringApplication.run(DailyApplication.class, args);

See if there is an error log.

@Slf4j
@EnableScheduling
@EnableFeignClients(basePackages = "com.iot")
@SpringBootApplication(scanBasePackages={"com.iot"})
@MapperScan({"com.iot.daily.*.dao"})
public class DailyApplication implements ApplicationRunner {

    public static void main(String[] args) {
        try {
            SpringApplication.run(DailyApplication.class, args);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error: ============== ", e);
        }
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("The daily report system was successfully launched!......");
    }
}

Start the project, and then, as expected, the console displays the error log with the following error message:

Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

The specific error information will be supplemented later, but now it can’t be reproduced.

3、 Solutions

Here is my project solution, very simple, Maven clean once, and then restart.

end!

[Solved] The version of springcloud must support the current version of springboot, otherwise the startup project will report an error: error starting ApplicationContext

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2021-06-26 15:42:31.976 ERROR 208496 — [           main] o.s.b.d.LoggingFailureAnalysisReporter   :
***************************
APPLICATION FAILED TO START
***************************
Description:
Your project setup is incompatible with our requirements due to following reasons:
– Spring Boot [2.3.0.RELEASE] is not compatible with this Spring Cloud release train

Action:
Consider applying the following actions:
– Change Spring Boot version to one of the following versions [2.4.x, 2.5.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]

Disconnected from the target VM, address: ‘127.0.0.1:10542’, transport: ‘socket’
Process finished with exit code 1
Follow the prompts to upgrade the SpringBoot version or lower the SpringCloud version to make both support each other.The reason for the error is that when I followed the online tutorials to write the code, the SpringBoot version of the pom in the project automatically generated by IDEA was aligned with the tutorials and the project started with an error. In order to follow less errors, I downgraded the version of SpringCloud to be consistent with the one in the tutorial.

2020.03

Amend to read

Hoxton.SR8

Restart project OK