Tag Archives: java

[Solved] AndroidStudio Error: Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

Error: Could not initialize class com.android.sdklib.repository. AndroidSdkHandler@TOC

After studio installs or upgrades to 4.2 + for the first time, an error is reported in the construction project. The reason is very simple, because the Java path configured for the project is wrong

because the default JDK path of the project will become the JDK path of studio after updating the version. At this time, you need to add your SDK as Java in the “environment variable”_ Home, and then the JDK path of the project must be the same as Java_Home remains the same and error is eliminated

The request was rejected because the URL contained a potentially malicious String “//“

Problem description

After the introduction of spring security, there is no problem using Vue proxy locally. There is a problem using nginx. The problem is located in the nginx configuration

Solution:

# rewrite ^(/api/?.*)$ /$1 break;  // old
 rewrite ^/api/(.*)$ /$1 break;    // modified

Explanation
take blog.lhuakai.top/api/getxxx as an example

nginx found /API , replaced the match to /api.getxxx/ with $1 (the content in the first group) getxxx and finally became blog.lhuakai.top/getxxx

When Maven hits the jar package, an error is reported when executing install, and the symbol cannot be found in a line

Record the problems encountered:

Since the problem has been solved before posting, there is no picture, please watch and think patiently!

Today, when preparing to deploy a project with a jar package, an error is reported in install. According to the idea prompt, it is locked in a line of a class

According to the error prompt, I found that I created a new class in package B, and the jar package I am typing is package a,

1. So I checked pom.xml in project a to see if the dependency of package B was introduced. It was confirmed that it had been introduced

2. I thought it might be that I didn’t print jar package for project B, so I tried to package project B first and then print package a

The too many open files solution appears in stream classes such as files.list

Problem scenario

In the background code of the blog, the design without database is adopted, and all information is based on the file system. When it comes to traversing some file information, the java.nio.file.files class and files.list are used for traversal. However, for stream methods such as files.list, if the resource is not closed, an error of too many open files will appear over time.

Solution

Use try with resource to automatically free resources.

Not improved:

...
Files.list(path).forEach(...)
...

Improved writing:

try (Stream<Path> fileList = Files.list(path)) {
    fileList.forEach(...)
} catch (Exception a) {
    ......
}

In this way, the open files will be automatically closed when using files.list to prevent errors. Similarly, it can also be used on other classes that inherit autoclosable, and subsequent problems will be sorted out.

Conclusion

The efficiency and rationality of the code still need to be considered, otherwise the preliminary test can’t see the problem, and it’s too late to regret for a long time.

The spring boot project directly replaces the referenced jar package

Shiro was used in an old spring boot project. Recently, Shiro broke a security vulnerability. So we need to upgrade the Shiro version in the project. However, this project was developed by former employees a long time ago, and the source code can no longer be found. So try to upgrade Shiro by replacing jar directly.

Wrong attempt

Usually, HTML can be replaced directly. JS can directly open WinRAR and replace the file directly. I thought jar packages can also be replaced directly. If you find that the jar is directly replaced, an error will be reported.

The error information is as follows:

java -jar spring-zs-1.0-update.jar                                                          [18:02:05]
Exception in thread "main" java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/shiro-web-1.5.3.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
	at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:285)
	at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:260)
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:248)
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:237)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:87)
	at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:72)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

Correct steps

Unpack through jar command

My project jar name is spring-zs-1.0. Jar

jar -xvf spring-zs-1.0.jar

After decompression, replace the jar package in./boot-inf/lib directory. I replaced Shiro — 1.2.2.jar with Shiro — 1.5.3.jar

Repackage

jar -cfM0 new.jar ./

This will generate a new jar package!

If you also use MacOS system, you should pay attention to one thing. The MacOS system will automatically generate
. DS in some directories_ Store files, so you should delete these hidden. DS files before repackaging_ Store, otherwise an error will be reported.

reference resources

https://blog.csdn.net/weixin_ 45417347/article/details/101539040

maven_ Unable to create servlet file under Java Web project

Add the following code in pom.xml:

<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>4.0.1</version>
   <scope>provided</scope>
</dependency>
 
<!-- https://mvnrepository.com/artifact/jstl/jstl -->
<dependency>
   <groupId>jstl</groupId>
   <artifactId>jstl</artifactId>
   <version>1.2</version>
</dependency>

[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

Invalidstorage.notfound when uploading video in alicloud VOD

Use Java SDK to upload video files according to official documents

  In the end, it will report an error

InvalidStorage.NotFound
The StorageLocation does not exist.  

View the cause of the error in the official document

If the set storage address does not exist, log in to the on demand console and select configuration management  & gt;   Media asset management and allocation  & gt;   Storage management   Check and confirm in.

  But I will still report an error after setting the default storage address (the default code is Shanghai)

The solution here is

Manually set in the code and then upload it

The above code is the local upload video, other ways of streaming and other solutions are the same.

Network error — browser error [How to Solve]

Record it! After half a month of internship, when I changed the bug today (an interface for modifying personal information), it was obviously changed, and the test environment was running smoothly. When I opened the test environment demonstration, I click submit to modify and report an error network error as shown in the following figure

I opened F12 to view the request, and found that the status was CORS error. My first feeling was that there was a cross domain problem, but I should not, Just opened the console and reported an error, as shown in the figure below:

I still feel that it is cross domain, but it should not be cross domain ~
finally, I found that the top left corner of the browser is as shown in the figure

remember that the company’s domain name has a certificate, is it because there is no s, so I changed the address bar HTTP to HTTPS, The problem is solved ~
then the cross domain reason should be that http//: test.xxx.com visited the interface of HTTPS: test.xxx.com, while the domain name allowed to cross domain in the background is http//: test.xxx.com https://test.xxx.com , which leads to cross domain ~
lack of talent and learning, misunderstanding and mistakes, please give us some advice in the comments area~