Note that there are some explanatory texts on larger screens.

plurals
  1. PO@Value annotation from Spring3 doesn't work in my program
    primarykey
    data
    text
    <p>I'm writing a java application with Spring 3.It's working well with xml,but not working at all in annotation.</p> <p>here's my snippet:</p> <pre><code>@Service("oracleDB") public class OracleDatabase implements IDatabase { @Value("oracle.jdbc.driver.OracleDriver") private String driverName; @Value("jdbc:oracle:thin:@") private String url; public String getDriverName() { return driverName; } } </code></pre> <p>My ApplicationContext.xml is like this:</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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.pdiwt.database"&gt;&lt;/context:component-scan&gt; &lt;/beans&gt; </code></pre> <p>MyInvoker is like that:</p> <pre><code>public class MyInvoker{ public static void main(String args[]){ XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml")); OracleDatabase oracelDB = beanFactory.getBean("oracleDB"); System.out.println(oracleDB.getDriverName()); } } </code></pre> <p>guess what? The result is null. Is there anything wrong?</p>
    singulars
    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.
 

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