Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to @autowire implementation of the class from a jar file?
    primarykey
    data
    text
    <p>I have a simple class and would like to use @Autowired to trigger the method from numberHandler object. However the object is null. Any ideas? </p> <pre><code>@Component public class Startup implements UncaughtExceptionHandler { @Autowired private MyHandler myHandler; public static void main(String[] args) { startup = new Startup(); startup(args); } public static void startup(String[] args) { startup = new Startup(); } private void start() { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); myHandler.run(); //NULL } </code></pre> <p>applicationContext.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"&gt; &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.my.lookup"/&gt; </code></pre> <p></p> <p>and the implementation class:</p> <pre><code>package com.my.lookup; @Component public class MyHandler implements Runnable { private static Logger LOGGER = LoggerFactory.getLogger(MyHandler.class); @Override public void run() { // do something } </code></pre> <p>Do I have to explicit define applicationContext.xml in main class with ClassPathXmlApplicationContext() or is there way for Spring to automatically recognize it in my classpath?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload