/**
 * The MIT License
 *
 * Copyright 2014 Ivar Grimstad <ivar.grimstad@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package eu.agilejava.spring4.config;

import eu.agilejava.javaee7.AwsomeJavaEECounter;
import eu.agilejava.javaee7.SimpleJavaEECounter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Spring configuration.
 * Example how to manage beans manually by spring.
 * 
 * @author Ivar Grimstad <ivar.grimstad@gmail.com>
 */
@Configuration
@ComponentScan("eu.agilejava.spring4")
@EnableWebMvc
public class ApplicationConfig extends WebMvcConfigurerAdapter {

   /**
    * Produces a spring managed simple counter.
    * @return simple counter
    */
   @Bean
   public SimpleJavaEECounter simpleJavaEECounter() {
      return new SimpleJavaEECounter();
   }
   
   /**
    * Produces a spring managed awsome counter.
    * @return awsome counter
    */
   @Bean
   public AwsomeJavaEECounter awsomeJavaEECounter() {
      return new AwsomeJavaEECounter();
   }
}

@@ -1274,24 +1274,233 @@
 aEECounter;%0A
+import java.util.logging.Logger;%0Aimport javax.enterprise.context.spi.CreationalContext;%0Aimport javax.enterprise.inject.spi.BeanManager;%0Aimport javax.naming.InitialContext;%0Aimport javax.naming.NamingException;%0A
 import org.s
@@ -1535,24 +1535,24 @@
 ation.Bean;%0A
-
 import org.s
@@ -1843,19 +1843,16 @@
 uration.
-%0A *
  Example
@@ -1894,17 +1894,16 @@
 ring.%0A *
- 
 %0A * @aut
@@ -2082,16 +2082,102 @@
 dapter %7B
+%0A   %0A   private static final Logger LOGGER = Logger.getLogger(%22Spring 4 Application%22);
 %0A%0A   /**
@@ -2217,32 +2217,38 @@
 simple counter.%0A
+    *%0A
     * @return si
@@ -2343,20 +2343,27 @@
  return 
-new 
+getCDIBean(
 SimpleJa
@@ -2373,25 +2373,30 @@
 ECounter
-(
+.class
 );%0A   %7D%0A
    %0A   /
@@ -2387,20 +2387,17 @@
 );%0A   %7D%0A
-   
 %0A
+
    /**%0A 
@@ -2439,24 +2439,30 @@
 me counter.%0A
+    *%0A
     * @retur
@@ -2540,32 +2540,32 @@
 vaEECounter() %7B%0A
-
       return new
@@ -2593,10 +2593,720 @@
 );%0A   %7D%0A
+   %0A   private %3CT%3E T getCDIBean(Class%3CT%3E t) %7B%0A      BeanManager bm = getBeanManager();%0A      javax.enterprise.inject.spi.Bean%3CT%3E bean = (javax.enterprise.inject.spi.Bean%3CT%3E) bm.getBeans(t).iterator().next();%0A      CreationalContext%3CT%3E ctx = bm.createCreationalContext(bean);%0A      T cdiBean = (T) bm.getReference(bean, t, ctx);%0A      return cdiBean;%0A   %7D%0A   %0A   private BeanManager getBeanManager() %7B%0A      try %7B%0A         InitialContext initialContext = new InitialContext();%0A         return (BeanManager) initialContext.lookup(%22java:comp/BeanManager%22);%0A      %7D catch (NamingException e) %7B%0A         LOGGER.severe(() -%3E %22Could not look up initialcontext: %22 + e.getMessage());%0A         return null;%0A      %7D%0A   %7D%0A
 %7D%0A

support for cdi lookup from spring