- error

Caused by: java.lang.IllegalStateException: More than one TaskExecutor bean exists within the context, and none is named 'taskExecutor'. Mark one of them as primary or name it 'taskExecutor' (possibly as an alias); or specify the AsyncConfigurer interface and implement getAsyncExecutor() accordingly.

at org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor.setBeanFactory(AsyncAnnotationBeanPostProcessor.java:135)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1597)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1565)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

... 20 more

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.core.task.TaskExecutor] is defined: expected single matching bean but found 6: clientOutboundChannelExecutor,messageBrokerTaskScheduler,clientInboundChannelExecutor,brokerChannelExecutor,taskScheduler,defaultSockJsTaskScheduler

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:366)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)

at org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor.setBeanFactory(AsyncAnnotationBeanPostProcessor.java:128)

... 23 more




- resolved
* Add the bean at Spring application context configuration

@Configuration
@EnableAsync
public class AppContext extends WebMvcConfigurationSupport {
...

@Bean
public Executor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}

}




'Framework & Platform > Spring' 카테고리의 다른 글

ThreadPoolTaskScheduler initialize method  (0) 2020.03.29
spring - ServletContext  (0) 2015.07.16
spring - headers="Accept=*/*"  (0) 2014.12.26
spring - Get current ApplicationContext  (0) 2014.10.06
spring - restTemplate example  (0) 2014.09.12
Posted by linuxism
,


public interface ServletContext
Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.

There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.)

In the case of a web application marked "distributed" in its deployment descriptor, there will be one context instance for each virtual machine. In this situation, the context cannot be used as a location to share global information (because the information won't be truly global). Use an external resource like a database instead.

The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.



source - http://docs.oracle.com/javaee/7/api/javax/servlet/ServletContext.html




* tomcat 구현 

org.apache.catalina.core

Class ApplicationContextFacade

  • All Implemented Interfaces:
    ServletContext


    public class ApplicationContextFacade
    extends Object
    implements ServletContext
    Facade object which masks the internal ApplicationContext object from the web application.

org.apache.catalina.core

Class ApplicationContext

  • All Implemented Interfaces:
    ServletContext
    Direct Known Subclasses:
    ReplicatedContext.ReplApplContext


    public class ApplicationContext
    extends Object
    implements ServletContext
    Standard implementation of ServletContext that represents a web application's execution environment. An instance of this class is associated with each instance of StandardContext.

- HttpSession.getServletContext() 호출 시 ApplicationContextFacade를 얻을 수 있음. ApplicationContextFacade 생성자 호출 시 ApplicationContext를 인자로 넘김

ApplicationContext.attributes(protected Map<String,Objectattributes = new ConcurrentHashMap<>())에서 web.xml 정보 확인할 수 있음


source - https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/core/ApplicationContextFacade.html

https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/core/ApplicationContext.html



* spring에서 WebApplicationContext를 얻기(Find a custom WebApplicationContext for this web app.)

org.springframework.web.context

Interface WebApplicationContext

source - http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/context/WebApplicationContext.html


- org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(ServletContext sc, String attrName) 호출

- sc는 ApplicationContextFacade에 해당하고 attrName은 web.xml에서 설정한 DispatcherServlet 서블릿 이름

- web.xml 설정을 javaConfig(WebApplicationInitializer)로 대체한 경우 ContextLoaderListener으로 등록되어 WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)을 호출해야하며 이 메서드는 attrName을 org.springframework.web.context.WebApplicationContext.ROOT으로 하여 WebApplicationContextUtils.getWebApplicationContext(ServletContext sc, String attrName)를 호출함

- 소스코드 

Object attr = sc.getAttribute(attrName);

return (WebApplicationContext) attr;

- 이후 WebApplicationContext를 통해서 bean을 얻을 수 있음 

UserService userService = (UserService) webApplicationContext.getBean("userService");



Posted by linuxism
,


Window self Property

Window Object Reference Window Object

Example

When the "Check window" button is clicked, the function check() is called and the current window status is checked. If the topmost window (window.top) is different from the current window (window.self), then output that "This window is not the topmost window! Am I in a frame?". If the topmost window equals the current window, then fire the else statement:

function myFunction() {
    if (window.top != window.self) {
        document.getElementById("demo").innerHTML = "This window is NOT the topmost window!";
    } else { 
        document.getElementById("demo").innerHTML = "This window is the topmost window!";
    } 
}

Try it yourself »

Definition and Usage

The self property returns the current window.

The self property is often used in comparisons (like in the example above).

This property is read-only.


Syntax

window.self

Technical Details

Return Value:A reference to the Window object itself




source - http://www.w3schools.com/jsref/prop_win_self.asp




Posted by linuxism
,