Tag Archives: java

[Solved] Fatal error LNK1169: one or more multiple defined symbols were found

Declare the global variable. The global function must be declared in CPP. If other classes refer to the global variable, include the H file of the CPP, and then extern. Otherwise, the repeated definition error is likely to occur.

How does this “easy” explain?

For example, if a global variable is declared in A.H

int Global;

In B.H

include "A.h"
.....
extern int Global;
......

If you include A.H, it is equivalent to including the declaration of global variables in A.H, and the compiler will consider it a duplicate definition.

Therefore, global variables and function declarations must be in CPP when The vs compiler reports this error when there is a function implementation in the H file.

Solution:
1 Yes Add inline
2 before the function declaration in H In project – > Attribute – > Linker – > Command line – > Add/force to additional options

The above is loaded from David_H

I also encountered this error, but the whole project contains too many files to analyze the inclusion relationship, but the problem should be similar.

my solution is:

Project – > Properties – > Linker – > Command line – > Add /force 

to additional options

It solved the error, but there were a lot of warnings.

[Siolved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘webMvcObject

Details of the problem are as follows:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webMvcObjectMapperConfigurer' defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.spring.web.WebMvcObjectMapperConfigurer] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.7.jar:2.5.7]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:765) [spring-boot-2.5.7.jar:2.5.7]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:445) [spring-boot-2.5.7.jar:2.5.7]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.7.jar:2.5.7]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) [spring-boot-2.5.7.jar:2.5.7]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.7.jar:2.5.7]
	at com.xx.xxApplication.main(xxApplication.java:12) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.5.7.jar:2.5.7]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.spring.web.WebMvcObjectMapperConfigurer] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.13.jar:5.3.13]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:305) ~[spring-context-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.3.13.jar:5.3.13]
	... 20 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_121]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_121]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_121]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.13.jar:5.3.13]
	... 27 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_121]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_121]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_121]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_121]
	... 31 common frames omitted


Process finished with exit code 0

The pom.XML file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.xx</groupId>
    <artifactId>xx</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>xx</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!--Web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--jdbc-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>2.5.7</version>
        </dependency>
        <!--Mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>
        <!--devtools-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <!--postgresql-->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--spring-boot-starter-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--restdocs-->
        <dependency>
            <groupId>org.springframework.restdocs</groupId>
            <artifactId>spring-restdocs-mockmvc</artifactId>
            <scope>test</scope>
        </dependency>
        <!--shiro-->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-web</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>1.5.3</version>
        </dependency>
        <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.25</version>
        </dependency>
        <!--gson-->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--swagger-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!--junit-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.asciidoctor</groupId>
                <artifactId>asciidoctor-maven-plugin</artifactId>
                <version>1.5.8</version>
                <executions>
                    <execution>
                        <id>generate-docs</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>process-asciidoc</goal>
                        </goals>
                        <configuration>
                            <backend>html</backend>
                            <doctype>book</doctype>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.restdocs</groupId>
                        <artifactId>spring-restdocs-asciidoctor</artifactId>
                        <version>${spring-restdocs.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>
        </plugins>
    </build>

</project>

Solution:

First, Check pom.xml file that we have excluded the jackjson , which comes with spring-boot-starter-web:

            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
            </exclusions>

Gson is used instead of Jackson :

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>

We also introduced the swagger dependency:

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

This is the problem. No matter which version of swaggerwe introduce, the above problems will occur, because swagger uses Jackson to convert JSON, but gson is incompatible with swagger.

Solution:

Use the default Jackson

Customize the configuration of Gson

[Solved] Maven Package Error: Error assembling JAR

Cause of the problem
the jar package prompted is occupied by other programs, so it is impossible to repackage and replace the old package

Solution:
1. If the jar package can be run, check whether the jar package is running and end the corresponding process
2. Check whether the read-write permission of the jar package has been changed and give the file read-write permission before operation
3. Check whether other software is editing the jar package file (such as compression software) and exit editing

How to Solve PIP3 install oct2py error

use sudo pip3 install oct2py error: ERROR: Cannot uninstall ‘pexpect’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
Solution: sudo pip3 install oct2py –ignore-installed pexpect
Install successfuly!

[Solved] jedis Error: Could not get a resource from the pool

The local Java program operates the redis service in the virtual machine and reports an error.

Solution:
1. check whether Linux in the local and VMware virtual machines can ping each otherwhen the Ping fails, it is usually the problem of setting the network adapter of the virtual machine. Refer to the correct configuration: 1) right click virtual machine -> Settings -> network adapter -> bridge mode. 2) Set IP4 in VMnet1 in the local network connection to automatic acquisition. 3) Set the network card of the virtual machine to get automatically. 4) Turn off the firewall of the local and virtual machines,

2. check whether redis can start normally, if it does not start normally, check the cause of the error through the log,

3. check whether the Java program reads the redis related configuration correctly, when reading the configuration, the field spelling error may cause the connection to redis to fail.

For example, @Value ("${spring.redis.host}")
host is written as port

MP Error: ‘getBaseMappe ServiceImpl’ clashes [How to Solve]

ServiceImp error:

‘getBaseMapper()’ in ‘com.baomidou.mybatisplus.extension.service.impl.ServiceImpl’ clashes with ‘getBaseMapper()’ in ‘com.baomidou.mybatisplus.extension.service.IService’; attempting to use incompatible return type

In MyBatis-plus, the general reference package is

com.baomidou.mybatisplus.core.mapper;

Looking at the source code, we can see that both the IService and its implementation class ServiceImpl require the Mapper

<M extends BaseMapper<T>, T>
ServiceImpl<M extends BaseMapper<T>, T> implements IService<T>

Problem solving: check whether the mapper used in the self-defined xxservicei is a subclass of basemapper, and

Mapper generic reference should be consistent with iservice.

[Solved] mybatisplus BaseMapper Error: required a single bean, but 2 were found

1. Error reporting

Two classes inherit com baomidou. mybatisplus. mapper. BaseMapper

Service startup error:

Field baseMapper in com.baomidou.mybatisplus.service.impl.ServiceImpl required a single bean, but 2 were found:

- UserDao: defined in file [D:\projects\test\UserDao.class]

- DepartmentDao: defined in file [D:\projects\test\DepartmentDao.class]

The code is as follows

public interface UserDao extends BaseMapper<UserInfo>{ }

public interface DepartmentDao extends BaseMapper{ }

2. Error reporting reason

Departmentdao did not specify a generic type when inheriting basemapper

3. Solution:

Specifying generics when departmentdao inherits basemapper

public interface DepartmentDao extends BaseMapper<DepartmentInfo>{ }

[Solved] debug error: cloud netflix. eureka. EurekaDiscoveryClientConfiguration (IDEA package normally)

Description of the problem: IDEAL in the program compilation, packaging are whole into, debug on the error, the content is as follows:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration$EurekaHealthCheckHandlerConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration$EurekaHealthCheckHandlerConfiguration]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/actuate/health/SimpleStatusAggregator
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.13.jar:5.3.13]
 
     ......
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326) ~[spring-beans-5.3.13.jar:5.3.13]
    ... 17 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/actuate/health/SimpleStatusAggregator
    at org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration$EurekaHealthCheckHandlerConfiguration.<init>(EurekaDiscoveryClientConfiguration.java:64) ~[spring-cloud-netflix-eureka-client-3.1.0.jar:3.1.0]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_251]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_251]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_251]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_251]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.13.jar:5.3.13]
    ... 19 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.health.SimpleStatusAggregator
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_251]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_251]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_251]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_251]
    ... 25 common frames omitted

 

Error Analysis:
Add eureka.client.healthcheck.enabled=true in application.properties files

Solution:
1. add dependency in pom.xml

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

 

2. file->invalidate caches/restart

[Solved] Annotation Customize Error: ElementType cannot be resolved to a variable

In the development process, you may use custom annotations (this article uses custom annotations when using JWT) to report an error:

ElementType cannot be resolved to a variable

Manually import packages:

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

Perfect solution