Hi,
i got java.lang.NullPointerException by using CrudRepository
my project looks like this:
strut2 action
service
repository
domain
here is the applicationContext.xml:Code:class Action { @Autowired MyService service; public String execute(){ service.getList(); return "ok"; } } interface Service { List getList(); } @org.springframework.stereotype.Service class ServiceImpl implements Service { @Autowired MyRepository repo; List getList(){ return (List)repo.findAll(); } } package com.mycompany.repositories; interface MyRepository extends CrudRepository<MyPojo, String>{}
I'm new here, and everytime i call the Action class, the service is injected, but MyRepository is alway null.Code:<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <jpa:repositories base-package="com.mycompany.repositories" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" > <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> </property> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="persistenceUnitName" value="unit-name" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="database" value="POSTGRESQL"/> </bean> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="username" value="root" /> <property name="password" value="root" /> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://127.0.0.1:5432/mydb" /> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
could someone help me with please, if you need more infos, pls let me know, thx!


Reply With Quote
