Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:00:50+00:00 2026-06-06T12:00:50+00:00

i got java.lang.NullPointerException by using CrudRepository my project looks like this: strut2 action service

  • 0

i got java.lang.NullPointerException by using CrudRepository

my project looks like this:

strut2 action

service

repository

domain

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>{}

here is the config:

  <?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>

I’m new here, and everytime i call the Action class, the service is injected, but MyRepository is alway null.

could someone help me with please, if you need more infos, pls let me know, thx!

EDIT 1

StackTrace:

2012-06-26 15:33:32,041 INFO  - com.myproject.action.project.preparation.ApplicationAction - listing application...
java.lang.NullPointerException
    at com.myproject.service.impl.ApmProjectPreparationServiceImpl.getAllApplications(ProjectPreparationServiceImpl.java:41)
    at com.myproject.action.project.preparation.ApplicationAction.listAction(ApplicationAction.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)

I also tried to debug it by myself. i found on the class ServiceImpl that the @Autowired MyRepository repo is null.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:00:54+00:00Added an answer on June 6, 2026 at 12:00 pm

    Seems i found the answer, thank @MartenDeinum from Spring Forum.

    here are the tricks:

    1. i am using struts2 for the GUI, so i need struts2 spring plugin to rewrite the struts2 object factory, so that the spring can find struts action.

    2. i added this config for @Service

      <context:component-scan base-package="com.myproject" />
      

      basically i also need

      <jpa:repositories base-package="com.myproject.repository" />
      

      to find CrudRepository.

    hope this can help others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I got something like this ERROR/AndroidRuntime(18677): Caused by: java.lang.NullPointerException ERROR/AndroidRuntime(18677): at com.companyname.a.a.a(Unknown Source)
I cant find why I got a java.lang.ArithmeticException: Invalid operation while using big decimal.
I got this error E/AndroidRuntime(475): java.lang.NoClassDefFoundError: com.google.gdata.client.youtube.YouTubeService When I try to run Youtube data
So I've got some Java code that uses Jakarta HttpClient like this: URI aURI
I got a java.lang.NullPointerException when I try to call createBitmap. Here is my code:
I'm trying to use ShareActionProvider with actionbarsherlock, but i got: java.lang.NullPointerException at com.iuculano.tvitaliane.Start.onCreateOptionsMenu(Start.java:387) at
i got this error in the logcat 06-21 11:58:27.275: E/AndroidRuntime(404): java.lang.RuntimeException: Unable to start
While compiling a program in Java I got this big WARNING warning: [unchecked] unchecked
I develop an app using PhoneGap. I got a service which is in background
got code looking like this: // This is com.n.common.Networking.downloadBmp( ) function // ... byte[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.