Author Archives: Robins

Spring AOP uses AspectJ to report an exception that ‘the reference to the bean “mypointcut” cannot be resolved’

"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\lib\idea_rt.jar=62844:E:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\bin" -Dfile.encoding=UTF-8 -classpath "E:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\lib\idea_rt.jar;E:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\plugins\junit\lib\junit-rt.jar;E:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\plugins\junit\lib\junit5-rt.jar;E:\myReposi\org\junit\platform\junit-platform-launcher\1.5.0-M1\junit-platform-launcher-1.5.0-M1.jar;E:\myReposi\org\apiguardian\apiguardian-api\1.0.0\apiguardian-api-1.0.0.jar;E:\myReposi\org\junit\platform\junit-platform-engine\1.5.0-M1\junit-platform-engine-1.5.0-M1.jar;E:\myReposi\org\opentest4j\opentest4j\1.1.1\opentest4j-1.1.1.jar;E:\myReposi\org\junit\platform\junit-platform-commons\1.5.0-M1\junit-platform-commons-1.5.0-M1.jar;E:\myReposi\org\junit\jupiter\junit-jupiter-engine\5.5.0-M1\junit-jupiter-engine-5.5.0-M1.jar;E:\myReposi\org\junit\jupiter\junit-jupiter-api\5.5.0-M1\junit-jupiter-api-5.5.0-M1.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\out\production\com.springStudy2;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-aop-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-aspects-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-context-support-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-expression-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-instrument-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-instrument-tomcat-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-jdbc-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-jms-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-messaging-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-orm-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-oxm-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-test-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-tx-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\commons-logging-1.2.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\aopalliance-1.0.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-beans-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-core-4.3.18.RELEASE.jar;D:\java_work\IDEA_work\javaSsmStudy_Spring\com.springStudy2\lib\spring-context-4.3.18.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.spring_aop2.MainTest,testSpringAop
五月 29, 2019 10:03:36 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@29b5cd00: startup date [Wed May 29 22:03:36 CST 2019]; root of context hierarchy
五月 29, 2019 10:03:36 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [com/spring_aop2/applicationContext.xml]

五月 29, 2019 10:03:38 下午 org.springframework.context.support.ClassPathXmlApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserServiceId' defined in class path resource [com/spring_aop2/applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot resolve reference to bean 'myPointCut' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPointCut': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserServiceId' defined in class path resource [com/spring_aop2/applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot resolve reference to bean 'myPointCut' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPointCut': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at com.spring_aop2.MainTest.testSpringAop(MainTest.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:117)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:185)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:181)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:128)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Cannot resolve reference to bean 'myPointCut' while setting bean property 'pointcut'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPointCut': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1284)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102)
	at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1045)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1019)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473)
	... 61 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPointCut': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1163)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1107)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:331)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
	... 77 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155)
	... 83 more
Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
	at java.lang.Class.getConstructor0(Class.java:3075)
	at java.lang.Class.getDeclaredConstructor(Class.java:2178)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
	... 84 more
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
	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)
	... 89 more


Process finished with exit code -1

Add AspectJWeaver -x.x.x Jar to namespace. Add AspectJWeaver -x.x.x Jar to namespace

shiro Error org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type

Recently I’m working on a small module using Spring MVC + MyBites + Spring Shiro

When making Shiro’s Realm auto-inject, it always gets an error.
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sam.project.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:618)
… 44 more

Entangled for a long time, finally found a solution on the Internet
Shiro’s Realm is a Filte, so when it is loaded in web.xml, it will load Filete before Spring, so @Autowired will never be able to find the bean in the Realm. In fact, after the container is started, the Web.xml configuration load order is
ServletContext – context – param – the listener – filter – servlet
Therefore, simply load the Spring configuration file in advance, i.e., place the Spring configuration file before the Shiro configuration file in web.xml, as shown below:

After the above configuration changes, restart the service!
The rest of the injection configuration remains the same, there is no need to set any @Resource, the previous @Autowired will be used.

[Fixed]ERROR: canceling statement due to conflict with recovery

ERROR: canceling statement due to conflict with recovery
Error Details:

ERROR: canceling statement due to conflict with recovery
DETAIL: User query might have needed to see row versions that must be removed.

Business again

    1. system USES postgresql main library database architecture, main library used in WeChat small program mainly used in the business of writing data from library with the method of flow to copy from the main library update for library data, for the application of the library service is the background of query statistics web applications when the query statistics in the background, the SQL query is slower, table is updated data, and the query used to query for a long time will be following the above error </ ol>
    1. Question why
    1. Executive time on the main library query process, due to this query involves records may be updated, or deleted in the main library, according to the PostgreSQL MVCC mechanism, update, or delete data is not immediately deleted from the physical block, but after autovacuum process VACUUM data of the old version, the main library to update, or delete data on the old version, after VACUUM from the library will also carry out the operation, thus conflict with from the current query library, cause the query to interrupt and throw more mistakes.
    1. The solution
    1. On a business level
    1. From the business can optimize the slow SQL, whether the data table is too large, whether need to separate the database table, frequently update the frequent table analysis and vacuum and so on. Or segmenting query, avoid peak period data update time, etc
    1. From the database level
    1. Modify the maxSTANDBY_ STREAMING_DELAY parameter
    1. This parameter for 30 seconds, by default when executing SQL for library, may have clashed with is application of a WAL, this query if there is no execution is suspended for 30 seconds, 30 seconds note not for library individual queries allow maximum execution time, refers to allow maximum when case library application on a WAL WAL delay time, so for library query execution time may be less than the value of this setting has been suspended, this parameter can be set to 1, said from the library when WAL application process and executed queries from the library, a WAL application process waits until from the database query execution. (When I was processing, I set a larger value of 120, although occasionally an error will be reported, but the frequency of error will be much less, it is suggested that this exception can be caught in background processing, and the query user will be reminded that the query is currently busy, please try again later)
    1. Modify the hotstandby_feedback parameter
    1. By default when performing a query from the library will not notify the main library, set this parameter to on after from library to execute queries will notify the main library, when from library query execution process, the main library won’t clean up the data from library need old version, therefore, the query from the library will not be suspended, however, this method also can bring certain disadvantages, table may appear on the main library expansion, the expansion of the main library table level and on the table write transactions and execution time from the library, this parameter is off by default. (This approach is risky, I haven’t tested it)
    After modifying the parameter configuration, you need to reload the database configuration file

Typeerror in Python regular expression: expected string or bytes like object

The following error occurs when parsing web page data with beautifulSoup and processing data with regular expressions:
TypeError: Expected string or bytes-like object TypeError: Expected string or bytes-like object TypeError: Expected string or bytes-like object
It is generally caused by data type mismatch.
There are six standard data types in Python3: 

Print (type(object)) to check the current data type, where object is the object to query.

First, there is a code that looks like this:

import re
import requests
from bs4 import BeautifulSoup
import lxml

#get the html data
urlSave = "https://www.douban.com/people/yekingyan/statuses"
req = requests.get(urlSave)
soup = BeautifulSoup(req.text,'lxml')

# After parsing beautifulsoup, get the required data
times = soup.select('div.actions > span')
says = soup.select('div.status-saying > blockquote')

And then I’m going to look at it and I’m going to get the data what is the numeric type

print('says:',type(says))

The result: Says: lt; class ‘list’>
This tells us that the data selected from beautifulSoup in soup.select() is of the list type.
Next, extract the data in the list separately

#Traversing the output
for say in says:
    print(type(say))

Let’s see what type it is
The result: <<; class ‘bs4.element.Tag’> , different from the above six types
Beautiful Soup converts a complex HTML document into a complex tree structure, where each node is a Python object. All objects can be classified into four types:
TagNavigableStringBeautifulSoupComment
Use regular expressions directly to the data

for say in says:
    # Regular expressions to get the necessary data
    say = re.search('<p>(.*?)</p>',say)

There is an error
TypeError: expected string or bytes-like object
Therefore, before the regular expression, the problem is solved by converting the data type. As follows:

for say in says:
    # Convert the data type, otherwise an error will be reported
    say = str(say)
    # Regular expressions to get the necessary data
    say = re.search('<p>(.*?)</p>',say)

 

Maven project running servlet jump JSP error: HTTP status 500 – unable to compile class for JSP

Runtime environment: JDK1.8 + Tomcat 6.0. x (maven comes with)

1. Error details

exception:
org.apache.jasper. JasperException: Unable to compile class for JSP:
An error occurred at line: 1 in the generated java file
The type java.io. ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files…


Look at the console error again

2. the cause of the problem:
maven use skeleton to create web projects, the default tomcat is 6.0, tomcat version is too low or jdk version is high.
3. problem solving:
Method 1: Use a high version of tomcat. Method 2: Use a lower version of jdk. I was using jdk1.8, the results reported an error. After replacing jdk1.7, it ran successfully without errors.

Run successfully:

Java: How to Find the Minimum Value from a Random Array by Bubble Sort Method

public class HelloWorld{
  public static void main(String[] args){
	  int[] a = new int[5];
      a[0] = (int) (Math.random() * 100);
      a[1] = (int) (Math.random() * 100);
      a[2] = (int) (Math.random() * 100);
      a[3] = (int) (Math.random() * 100);
      a[4] = (int) (Math.random() * 100);
       
      System.out.println("The individual random numbers in the array are :");
      for (int i = 0; i < a.length; i++)
          System.out.println(a[i]);
       
      System.out.println("bubble sorting method: (compare two by two, put the bigger one behind)");
      for (int j = 0; j < a.length; j++) {
          for (int i = 0; i < a.length-j-1; i++) {
              if(a[i]>a[i+1]){  
                  int temp = a[i];
                  a[i] = a[i+1];
                  a[i+1] = temp;
              }
          }
      }
      System.out.println("the minimum number is"+a[0]);
  }
}

[Fixed]No bean named ‘sqlSessionFactoryBean’ available

SpringBoot integration with mybatis service startup exception log

2019-09-18 19:52:17.270  WARN 8320 — [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory. BeanCreationException: Error creating bean with name ‘testDtoMapper’ defined in file [D:\workspace\xesWorkspace\xes\target\classes\com\xes\www\core\mapper\TestDtoMapper. class]: Cannot resolve reference to bean ‘sqlSessionFactoryBean’ while setting bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory. NoSuchBeanDefinitionException: No bean named ‘sqlSessionFactoryBean’ available

Check the code and the introduction of jar packages no problem, the problem is the database data source and sqlSessionFactory is not integrated into a piece
maven configuration

<!--spring boot Integrating mybatis dependencies-->
<dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>2.0.0</version>
</dependency>
<dependency>
   <groupId>org.mybatis</groupId>
   <artifactId>mybatis-spring</artifactId>
   <version>1.3.2</version>
</dependency>
<!-- It is not necessary to refer to the following jar package https://mvnrepository.com/artifact/org.apache.ibatis/ibatis-core -->
<!--<dependency>
   <groupId>org.apache.ibatis</groupId>
   <artifactId>ibatis-core</artifactId>
   <version>3.0</version>
</dependency>-->

Mybatis configuration class

@Configuration
@MapperScan(basePackages = {
        "com.xes.www.core.mapper"
}, sqlSessionFactoryRef = "sqlSessionFactoryBean")
public class MybatisConfiguration {
    // Replaces the traditional datasource binding sqlSessionFactoryBean
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        return sqlSessionFactoryBean;
    }
}

So here’s the traditional configuration which is configured through XML

< ! – let Spring manage SQLSessionFactory using MyBatis and Spring integration ->;
<  bean id=”sqlSessionFactory” class=”org.mybatis.spring.SqlSessionFactoryBean”>
< ! — database connection pooling –>;
<  property name=”dataSource” ref=”dataSource” />
< ! — Loading MyBatis global configuration file –>
< property name=”configLocation” value=”classpath:mybatis/SqlMapConfig.xml” />
< /bean>

Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command

Error:
Traceback (most recent call last):
File “D:\PyCharm Edu 2020.3.3\plugins\python-ce\helpers\pydev\pydevconsole. py”, line 5, in
from _pydev_comm. pydev_rpc import make_rpc_client, start_rpc_server, start_rpc_server_and_make_client
File “D:\PyCharm Edu 2020.3.3\plugins\python-ce\helpers\pydev_pydev_comm\pydev_rpc. py”, line 4, in
from _pydev_comm. pydev_server import TSingleThreadedServer
File “D:\PyCharm Edu 2020.3.3\plugins\python-ce\helpers\pydev_pydev_comm\pydev_server. py”, line 4, in
from _shaded_thriftpy. server import TServer
File “D:\PyCharm Edu 2020.3.3\plugins\python-ce\helpers\third_party\thriftpy_shaded_thriftpy\server. py”, line 9, in
from shaded_thriftpy. transport import (
File “D:\PyCharm Edu 2020.3.3\plugins\python-ce\helpers\third_party\thriftpy_shaded_thriftpy\transport_init. py”, line 57, in
from .sslsocket import TSSLSocket, TSSLServerSocket # noqa
File “D:\PyCharm Edu 2020.3.3\plugins\python-ce\helpers\third_party\thriftpy_shaded_thriftpy\transport\sslsocket. py”, line 7, in
import ssl
File “D:\Anaconda\lib\ssl. py”, line 98, in
import _ssl # if we can’t import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified program could not be found.

How to Fix this error
Link: https://stackoverflow.com/questions/54175042/python-3-7-anaconda-environment-import-ssl-dll-load-fail-error
Copy the following files from anaconda\Library\bin to anaconda/DLLs
libcrypto-1_1-x64.dlllibssl-1_1-x64.dll

SQL Server Group sort de duplication row_ number() over ( PARTITION BY t1.col_ 2 ORDER BY 1 )

Recall SQLServer group sort once to reanalyze

row_number() over ( PARTITION BY t1.col_2 ORDER BY 1 )

-- Code
DELETE FROM table_name t 
WHERE t.rowid IN (
	SELECT rid
	FROM(
		SELECT t1.rowid rid,row_number() over ( PARTITION BY t1.col_2 ORDER BY 1 ) rn 
		FROM table_name t1 
	) t1 
	WHERE t1.rn > 1 
);

-- PARTITION BY t1.col_2
-- The first grouping is based on the second column

-- ORDER BY 1
-- then sort by the first column

-- row_number()
-- reassign row numbers to the grouped sorted data
-- similar to a grouped set of numbers
-- for example, the first two steps are divided into three groups
-- row_number() will renumber the first group from 1, 1.2.3.4 ....
-- the second group will still be numbered from 1, 1.2.3.4 ....
-- and so on down the line

-- WHERE t1.rn > 1
-- Filter the grouped sorted data to filter out all rows numbered greater than 1 (i.e. duplicate rows)
-- keep only the first record, filter all others greater than 1 and then use t.rowid IN () to delete them to achieve de-duplication

Python: How to Create an Automatic Recording Program

automatic recording program connects the radio station, if someone talking channel automatically recorded
all the recording stored in an audio file of a day, will record the start time, stop time, duration, the starting position in the recording, convenient and rapid positioning, no one spoke automatically stop recording, saving disk,
Multithreading technology, even if the program crashes the recording file will not be damaged
= = = = = = = = = =
Warning:
Please abide by the Radio Management Regulations of the People’s Republic of China when using this procedure. > Regulations of the People’s Republic of China on Radio Administration
This procedure is only used for learning and communication, and shall not be used for illegal purposes

import threading
import pyaudio
import copy
import math
import time
import numpy
import wave

localtime = time.localtime()
localtimestr = time.strftime("%Y-%m-%d-%H-%M-%S",localtime)
#ltime = time.time()
line = 0
class RecordThread(threading.Thread):
    def __init__(self, audiofile="C:/Users/Public/RE/"+localtimestr+".wav"):
        threading.Thread.__init__(self)
        self.bRecord = True
        self.rr = True
        self.audiofile = audiofile
        self.chunk = 1024
        self.format = pyaudio.paInt16
        self.channels = 1
        self.rate = 16000

    def run(self):
        #print("RUN....")
        audio = pyaudio.PyAudio()
        wavfile = wave.open(self.audiofile, 'wb')
        wavfile.setnchannels(self.channels)
        wavfile.setsampwidth(audio.get_sample_size(self.format))
        wavfile.setframerate(self.rate)
        wavstream = audio.open(format=self.format,
                               channels=self.channels,
                               rate=self.rate,
                               input=True,
                               frames_per_buffer=self.chunk)
        global xx
        global yy
        xx = 0
        yy = 0
        global line
        alltime = 0
        ntime1 = 0
        ntime2 = 0
        starttime = 0
        stoptime = 0
        timediff = 0
        while self.bRecord:
            data = wavstream.read(self.chunk)
            wavdata = numpy.fromstring(data,dtype=numpy.short)
            M = []
            for i in range(0,len(wavdata),16000):
                M.append(wavdata[i:i+16000]/10)
                M=map(abslist,M)
                sound = list(map(mean,M))
            if sound[0] > 50:
                #print("over")
                #Write
                xx = 1
                wavfile.writeframes(data)
            else:
                xx = 0
            if xx > yy:
                yy = 1
                #START
                starttime = time.time()
                alltime = round(alltime + timediff,3)
                
                log("StartTime: "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(starttime))+"    开始时间: "+timestr(alltime))
                print("StartTime: "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(starttime))+"    开始时间: "+timestr(alltime))
            if xx < yy:
                yy = 0
                #STOP
                stoptime = time.time()
                timediff = round(stoptime - starttime,3)
                
                srt(str(line)+"\n"+timestr(alltime)+" --> "+timestr(alltime+timediff)+"\n"+str(line)+"\n"+"<font color=#5F9F9F>"+time.strftime("%H:%M:%S",time.localtime(starttime))+"  ->  "+time.strftime("%H:%M:%S",time.localtime(stoptime))+"</font> "+"<font color=#4D4DFF>"+timestr(timediff)+"</font>"+"\n")
                line = line + 1
                log("StopTime:  "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(stoptime))+"    结束时间: "+timestr(alltime+timediff)+"\n")
                print("StopTime:  "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(stoptime))+"    结束时间: "+timestr(alltime+timediff))
                print("Time: "+timestr(timediff)+"\n")
                 
        wavstream.stop_stream()
        wavstream.close()
        audio.terminate()
        
    def stoprecord(self):
        print("stop")
        self.bRecord = False
        
    def pause(self):
        print("pause")
        self.rr = False
       
    def next(self):
        print("next")
        self.rr = True
        
def abslist(a):
    return list(map(abs,a))
def mean(a):
    return numpy.longlong(sum(a))/len(a)

def log(msg):
    with open('C:/Users/Public/RE/'+localtimestr+ '.txt','a+') as file:
        file.write(msg+"\n")
        file.close()

def srt(msg):
    with open('C:/Users/Public/RE/'+localtimestr+ '.srt','a+') as file:
        file.write(msg+"\n")
        file.close()

        
def timestr(sec):
    m,s = divmod(sec,60)
    h,m = divmod(m,60)
    return str("%d:%02d:%.2f"%(h,m,s))



    
rt = RecordThread()
line = line + 1
#print(timestr(2.65))

log("RUN ...... Start At "+localtimestr+"    SYS OK!"+"  Frequency:91.1Mhz")
srt(str(line)+"\n"+"0:00:00.0 --> 0:00:30.0\n"+"{\\an8}"+"<font color=#FFFF00>"+ str(time.strftime("%Y/%m/%d %H:%M:%S",localtime))+"</font>"+" <font color=#00FFFF>(20:00-21:00)</font>"+"\n"+"<font color=#00FF00>438.025 -5 88.5 <i>QTH Suzhou Jiangsu China</i></font>\n<font color=#3299CC>苏州市业余无线电 472752158</font>\n\n1\n0:00:00.0 --> 0:00:30.0\n{\\an5}请遵守<font color=#FF0000><u><b>《中华人民共和国无线电管理条例》</b></u></font>\n")
print("RUN ...... Start At "+localtimestr+"    SYS OK!"+"  Frequency:91.1Mhz")
rt.start()

Exception information: jsonmappingexception: out of start_ ARRAY token

JsonMappingException: out of START_ARRAY token
How to Fix this error
Json

[
  {
    "id": 4,
    "dmNum": "111102",
    "number": "683272",
    "parentNum": "0",
    "type": "1",
    "name": "dashen",
    "code": "213134",
    "mDefault": "37",
    "description": "please ask",
    "isDel": "0",
    "opFlag": "A",
    "createdBy": "creator",
    "createdTime": "2020-10-15T05:20:17.000+0000",
    "updatedBy": "deleter",
    "updatedTime": "2020-10-15T05:28:18.000+0000",
    "children": null,
    "parentName": null
  },
  {
    "id": 5,
    "dmNum": "111102",
    "number": "68327201",
    "parentNum": "683272",
    "type": "0",
    "name": "temperature data",
    "code": "213135",
    "mDefault": "95",
    "description": "I dont know",
    "isDel": "0",
    "opFlag": "A",
    "createdBy": "creator",
    "createdTime": "2020-10-15T05:20:18.000+0000",
    "updatedBy": "deleter",
    "updatedTime": "2020-10-15T05:27:33.000+0000",
    "children": null,
    "parentName": null
  }
]

Create ObjectMapper

    public static ObjectMapper mapper = new ObjectMapper();

    static {
        // Convert to formatted json
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        // If there are new fields in the json that do not exist in the entity class, no error will be reported
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        // Modify date format
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

Java code:

String s1 = httpAPIService
                    .doGet("http://192.168.0.25:8888/modeloutput/selectOutputByModelId?mid=" + mid);
            ModelOutput[] modelOutput =  mapper.readValue(s1, ModelOutput[].class);//Output Table Object
            for (ModelOutput output : modelOutput) {
                //Assignment: metadata number
                deviceOutput.setMetaNum(output.getNumber());
                //Assignment; data encoding
                deviceOutput.setCode(output.getOutputCode());
                deviceOutputMapper.save(deviceOutput);
                System.out.println(deviceOutput);
            }

The outermost layer of this string of JSON data is [], which represents an array of objects, because the Jackson Object Mapper is converting the returned JSON fragment into an object.
Convert to an array object

ModelOutput[] modelOutput =  mapper.readValue(s1, ModelOutput[].class);

Iterate through the data in the array. Convert to a Java object.
idea shortcut key: iter

for (ModelOutput output : modelOutput) {
                //Assignment: metadata number
                deviceOutput.setMetaNum(output.getNumber());
                //Assignment; data encoding
                deviceOutput.setCode(output.getOutputCode());
                deviceOutputMapper.save(deviceOutput);
                System.out.println(deviceOutput);
            }

Done!