java - spring injection without constructor and setter -


i have question. if class has dependency like:

public class test {    public depend depend;     //here methods } 

and does not have setter depend property or constructor depend argument, , has no annotation spring has xml config like:

<bean id="depend" class="xxx.depend"></bean>  <bean id="test" class="xxx.test">    <property name="depend" ref="depend" /> </bean> 

is possible inject depend test using such config (actually config not work. wonder - can change smth make work not using annotations or setter/constructor)?

it not possible without using annotations.

your current configuration needs simple changes make work. annotate depend field @autowired , enable component scanning.

here's detailed explanation: http://www.mkyong.com/spring/spring-auto-scanning-components/


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -