Tag Archives: spring

Spring integrates mybatis error reporting collection, summary and update

error: java.lang.noclassdeffounderror: org/AspectJ/Weaver/reflect/reflectionworld $reflectionworldexception

spring integration mubatis startup error:

Solution: at first glance, the error is due to the lack of package. The package here is missing: aspectjweaver.jar   This package is used by spring AOP. You can download and import this package online. Download address: http://download.csdn.net/detail/luojiming1990/5432831 ;

Error code:

 1 2017-04-01 09:15:46 [org.mybatis.spring.mapper.ClassPathMapperScanner]-[DEBUG] Creating MapperFactoryBean with name 'itemsMapper' and 'com.kjczwl.ssm.mapper.ItemsMapper' mapperInterface
 2 2017-04-01 09:15:46 [org.mybatis.spring.mapper.ClassPathMapperScanner]-[DEBUG] Creating MapperFactoryBean with name 'itemsMapperCustom' and 'com.kjczwl.ssm.mapper.ItemsMapperCustom' mapperInterface
 3 2017-04-01 09:15:46 [org.mybatis.spring.mapper.ClassPathMapperScanner]-[DEBUG] Creating MapperFactoryBean with name 'orderdetailMapper' and 'com.kjczwl.ssm.mapper.OrderdetailMapper' mapperInterface
 4 2017-04-01 09:15:46 [org.mybatis.spring.mapper.ClassPathMapperScanner]-[DEBUG] Creating MapperFactoryBean with name 'ordersMapper' and 'com.kjczwl.ssm.mapper.OrdersMapper' mapperInterface
 5 2017-04-01 09:15:46 [org.mybatis.spring.mapper.ClassPathMapperScanner]-[DEBUG] Creating MapperFactoryBean with name 'userMapper' and 'com.kjczwl.ssm.mapper.UserMapper' mapperInterface
 6 2017-04-01 09:15:46 [org.springframework.context.support.PropertySourcesPlaceholderConfigurer]-[INFO] Loading properties file from class path resource [db.properties]
 7 2017-04-01 09:15:46 [org.springframework.web.context.ContextLoader]-[ERROR] Context initialization failed
 8 java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
 9     at java.lang.Class.getDeclaredMethods0(Native Method)
10     at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
11     at java.lang.Class.getDeclaredMethods(Class.java:1810)
12     at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:159)
13     at org.springframework.context.annotation.ConfigurationClassUtils.isLiteConfigurationCandidate(ConfigurationClassUtils.java:104)
14     at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:87)
15     at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:253)
16     at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:240)
17     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
18     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:684)
19     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
20     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
21     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
22     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
23     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
24     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
25     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
26     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
27     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
28     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
29     at java.util.concurrent.FutureTask.run(FutureTask.java:166)
30     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
31     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
32     at java.lang.Thread.run(Thread.java:722)
33 Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
34     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
35     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
36     ... 24 more

 

 

 

error: needed exception is java.lang.noclassdeffounderror: org/aopalliance/intercept/methodinterceptor  

 

operating environment: jdk1.7.0_17 + tomcat 7 + eclipse

 

This error occurs when spring integration mybatis starts:

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/spring/applicationContext-transaction.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor

Solution:

Missing package: aopalliance.jar

To address:   http://sourceforge.net/projects/aopalliance/files/   Download the package and copy it to your project. If you see “ NoClassDefFoundError: XXXXXXXX ” in the future, you generally lack any package. Take a closer look at whether your project lacks any package

Aopalliance.jar function: this package is the API package of AOP alliance, which contains aspect oriented interfaces. Generally, spring and other frameworks with dynamic weaving function rely on this package

 

error: configuration problem: ID is required for element ‘advice’ when used as a top-level tag

an error is reported when spring integrates mybatis:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Configuration problem: Id is required for element ‘advice’ when used as a top-level tag

solution: the literal meaning is clear. When the tag “advice” is used as the top-level element, the tag needs the ID attribute,

        

 

“Java. Lang. NoClassDefFoundError: org / aopalliance / intercept / methodinterceptor” problem encountered in using spring

JavaScript implementation: how to write beautiful conditional expression>>>

Problem:
when using spring to declare transaction management, add definition annotation transaction & lt; tx:annotation-driven transaction-manager=”transactionManager”/> Java. Lang. noclassdeffoundation appears after rror:org/aopalliance/intercept/MethodInterceptor That’s the amount of money

analysis:
1. There is no jar package of aopalliance in the project, so downloading a corresponding jar to join the project can solve the problem
2. The jar package aopalliance is usually used by other frameworks with dynamic weaving function, such as spring. This package is the API package of AOP alliance, which contains the interface for aspect oriented

Failed to obtain JDBC Connection

Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
My mysql is 5.7.25 maybe there is a problem with the installation mysql time zone is not set just set the time zone

 

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=CST

Spring Error: Bean instantiation via factory method failed StackOverflowError

 

1. Phenomenon

When writing spring program normally, an error is reported suddenly:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'blogDao' defined in org.maoge.nameddemo.BeanConfig: 
Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.maoge.nameddemo.BlogDao]: Factory method 'blogDao' threw exception; 
nested exception is java.lang.StackOverflowError

2. Analysis and treatment

Several keywords: beancreationexception, beaninstantiation via factory method failed, beaninstantiationexception, stackoverflow error.

It can be analyzed that there is an error in the generated bean, and then we can see that there is a stackoverflow error indicating that there is a memory overflow, which should be caused by an infinite loop.

Look at the code:

	@Bean
	public BlogDao blogDao() {
		BlogDao blogDao=new BlogDao();
		blogDao.setNamedParameterJdbcTemplate(namedParameterJdbcTemplate());//注入namedParameterJdbcTemplate
		return blogDao();
	}

I’ll go. Blogdao () calls blogdao (), and I call myself.

To be amended as follows:

	@Bean
	public BlogDao blogDao() {
		BlogDao blogDao=new BlogDao();
		blogDao.setNamedParameterJdbcTemplate(namedParameterJdbcTemplate());//注入namedParameterJdbcTemplate
		return blogDao;
	}

It’s done!

Org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping

org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping

Reason: yml file format error, this file requires strict requirements format

If the nodes are not aligned, align the Mybatis nodes with the Spring nodes, here is the yml configuration file for SpringBoot 2.0 + Mybatis + Mysql

server:
port: 8080
spring:
datasource:
name: daducha
type: com.alibaba.druid.pool.DruidDataSource
druid:
url: jdbc:mysql://127.0.0.1:3306/daducha
username: root
password: root
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.wuji.entity.po

Spring Custome schema Loading Error: White spaces are required between publicId and systemId.

Spring project startup error

The error log is as follows:

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from URL [jar:file:webapps/ROOT/WEB-INF/lib/xxx-biz-1.0.jar!/xxx/sponsor-group-pipeline.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://www.xxx.com/schema/hipac/pipeline.xsd; lineNumber: 1; columnNumber: 50; White spaces are required between publicId and systemId.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:245) ~[spring-beans-4.1.9.RELEASE.jar:4.1.9.RELEASE]
    ... 54 common frames omitted
Caused by: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) ~[na:1.8.0_45]

Google has been saying for a long time that there should be a space between systemid and PublicID defined by XML header, which is the content of this lump

<?xml version="1.0" encoding="UTF-8"?&>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:hipac="http://www.xxx.com/schema/hipac"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.xxx.com/schema/hipac http://www.xxx.com/schema/hipac/pipeline.xsd"&>

It’s the red part above. You can see that there is no problem with my configuration

What’s the problem?At the beginning, I always suspected the jar package conflict, but after a long time of investigation, compared with many jar versions of other normal applications, no problem was found

Since this scheme is defined by myself, there is a corresponding configuration resolution in spring, that is spring.handlers and spring.schemas Two documents. Let’s look at the contents of these two documents

spring.handlers

http\://www.xxx.com/schema/hipac=com.xxx.engine.choreography.pipeline.namespace.EngineNamespaceHandler

spring.schemas

http\://www.xxx.com/schema/hipac/pipeline.xsd=com/xxx/engine/choreography/pipeline/xsd/pipeline.xsd

One of these two files specifies the path of XSD, and the other is the parsing class of schemas. It is suspected that there is a problem with the loading of these two files

So I searched these two files in the access application code, and found that there are actually these two configuration files in the application, and the contents are similar (only the values are different, and the corresponding class and XSD can’t be found in the code). I’m very suspicious here, and the probability is the problem.

Next, delete these two files immediately and deploy them again. OK, it’s successful.

After this problem, let me remember that another application had this situation when it was just connected, but I forgot how to solve it at that time. In retrospect, it was actually caused by the wrong class path or XSD path in the configuration file at that time.

However, the prompt for spring startup is also a pitfall. It’s too misleading. I always think it’s a problem with the referenced configuration file, which wastes a lot of time. I’ll take a good look at spring’s parsing of sechemas later.

What is Spring IoC ?

Before going through the Spring IoC tutorial, we must know what IoC is and why we use it in real life project development.

IoC or Inversion of Control, is also known as Dependency Injection, is used to create loosely coupled software components. Here, loosely coupled means less dependent software components. Let us illustrate it with an example:

There is a Report class used to generate reports of a bank account and ReportFileWriter is a class that creates a file and writes the report data to the file. Data is provided by the Report class to ReportFileWriter and in response it returns the file instance containing the report. So Report class is dependent on ReportFileWriter class. The dependency graph will be as follow:

Dependency Graph

In this situation Report class will create an instance of class ReportFileWriter and will call the method “createReport” by passing report data:

ReportFileWriter fw = new ReportFileWriter();
fw.createReport(data);

If you think carefully, in this code we are using tight coupled dependency between Report class and ReportFileWriter class. That means if we want to change the file writer class to PDFReportFileWriter in future we have to change the code of Report class. They are tightly coupled.

IoC solves the problem of tight couple and helps to makes the software component loosely coupled, so that we can maintain our code pretty much easily.

IoC or Inversion of Control is a design pattern that provided instances of a bean or class to another when they needed.That means, we do not have to use new keyword to create instance of dependent class. We will just create a reference of dependent class and IoC pattern will set the instance to the reference when needed.

Now, using IoC Report class will have following code :

ReportFileWriter fw = null;

Public void setFw(ReportFileWriter fw){
    this.fw = fw;
}

IoC container will call setter method to set the instance of ReportFileWriter class. We have to configure the dependency in our classes in IoC configuration file. That will tell the IoC container when and how to inject the dependences.

Creating a better loosely coupled model

In this session we will see how to IoC to create effective loosely coupled components. Consider the previous example of Report class. There is a interface named “ReportWriter” which contains following definition:

public interface ReportWriter {
    public File createReport(ReportData data);
}

Any class implementing ReportWriter interface will be able to create report file of its own format. The report class contains following code:

private ReportWriter reportWriter = null;

public void setReportWriter(ReportWriter rw){
    this.reportWriter = rw;
}

//More Code
reportWriter.createReport(data);
//More Code

Now, we want to provide a facility to generate report in two formats, in PDF and in MS Word. So we will create two classes PDFReportWrite and MSWordReportWriter which will implement the interface ReportWriter. We will configure our IoC container in such a way that when we will need a PDF Report the IoC container will create instance of PDFReportWrite and set to ReportWriter reference of Report class and if we need MS Word format then IoC container will create instance of MSWordReportWriter and set to ReportWriter reference of Report class. No more we have to change the code of Report class to generate a different format report. This is the advantage of IoC design pattern.

Types of Dependency Injection:

There are three ways in which a IoC container can inject dependency class instance to the dependent class:

Setter Injection: In this way, IoC container uses setter of the reference to set the instance of dependency class. Spring IoC provides setter Injection facility. We will learn about it with proper examples in next tutorial.

Constructor Injection: In constructor injection IoC container users construction of dependent class to set the instance of dependency class. We will see example of constructor injection in upcoming tutorials using Spring IoC framework.

Interface Injection:It is more complex process of dependency injection in which interfaces are used to inject the instances. Spring IoC container does not support this type of injection.

Call JIRA API to create issue prompt xsrf check failed

1. Check whether the client sending the request is httpclient or resttemplate in spring. It’s better to use resttemplate (I just want to replace the client). The request header is as follows. The rest is mei’jia

HttpHeaders headers = new HttpHeaders();
headers.add("X-Atlassian-Token", "no-check");
headers.add("Authorization", JIRA_API_AUTHORIZATION);
headers.add("Content-Type", "application/json");

2. Add configuration in the request header( headers.add (x-atlassian-token, no check); this is the advice given in the official document

3. Modify the user agent in the request header

It’s better to deal with the above items. Generally, this problem can be solved. In addition, post several JIRA API documents.

(create issue) https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api -Rest-api-2-issue-post headers.add (“Authorization”, JIRA_ API_ AUTHORIZATION))

(JIRA official document on security certification related content) https://developer.atlassian.com/server/framework/atlassian-sdk/atlassian-rest-api-design-guidelines-version-1/

(questions from others in JIRA community) https://community.atlassian.com/t5/Jira-questions/Jira-7-rest-api-XSRF-check-failed-for-post-issue-with/qaq-p/488706