Dostaję cały czas null w lini, gdzie jest pole.zapisz. Chyba nie wstrzykuje zależności, co jeszcze potrzebuje w konfiguracji, żeby to zadziałało?
@Service
public class KlasaTest {
@Autowired
private Klasa1Impl pole;
@Test
public void testMetody(){
ApplicationContext context = new ClassPathXmlApplicationContext("SpringBeans.xml");
System.out.println(context); //wypisuje adres obiektu
pole.zapisz(jakisObiekt);
}
}
@Repository
public class Klasa1Impl implements InterfejsDao {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource){
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
//jakies tam metody
}
<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/cache"
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/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<context:property-placeholder location="classpath:application.properties"/>
<context:component-scan base-package="com.pakiet.doskanowania"/>
<context:annotation-config/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>