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 8899587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:53:38+00:00 2026-06-15T00:53:38+00:00

My project works fine with autowired options as standalone and i create a jar

  • 0

My project works fine with autowired options as standalone and i create a jar file from this project.Problem comes after i added this jar to parent project, when i try to use external jar file’s class in my parent project i got error like “Exception in thread “main” java.lang.NullPointerException…”.

But if i don’t use autowired option in my external jar file and write code fill context manually.Then external jar file works fine with my parent project.

External Jar File With Autowired Class

public class UserService {


@Autowired 
UserRepository userRepository;

@Autowired
Movie2Repository movieRepository;

@Autowired
PersonRepository personRepository;


ConfigurableApplicationContext context;
public UserService(){
    // context = new ClassPathXmlApplicationContext("META-INF/spring/application-context.xml");
}


public void closeApp(){

    //context.close();
}

public void  insert(){
     //userRepository = context.getBean(UserRepository.class);
     System.out.println("user vvvv");
     User u = new User();
     u.firstname="dede";
     userRepository.save(u);
     System.out.println("user eklendi");

ApplicationContext file from external jar file

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
    http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- JPA -->

<context:property-placeholder
    location="/META-INF/spring/database.properties" />

<import resource="/database.xml"/>


<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

 <bean id="jpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="false" />
    <property name="database" value="MYSQL" />
</bean>


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="persistenceUnit" />
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>

<jpa:repositories base-package="org.springframework.data.example.jpa" />

Parent Project Package File

package abcdef;
import org.springframework.data.example.*; 
import org.springframework.data.example.jpa.UserService;
import org.springframework.data.example.jpa.UserService2;

public class abcde {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            UserService u= new UserService();
            u.insert();

        }


}

ApplicationContext file from parent project

<!-- JPA -->

<context:property-placeholder
    location="/META-INF/spring/database.properties" />

<import resource="/database.xml"/>

<import resource="classpath*:/META-INF/spring/*.xml" />


<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

 <bean id="jpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="false" />
    <property name="database" value="MYSQL" />
</bean>


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="persistenceUnit" />
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>

<jpa:repositories base-package="org.springframework.data.example.jpa" />

After we run parent project’s code i got the below error:

 user vvvv
Exception in thread "main" java.lang.NullPointerException
    at org.springframework.data.example.jpa.UserService.insert(UserService.java:47)
    at abcdef.abcde.main(abcde.java:13)
  • 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-15T00:53:40+00:00Added an answer on June 15, 2026 at 12:53 am

    Pretty simple. Your UserService isn’t wired because you created it with new and didn’t retrieved it from the spring context.

    public class abcde {
    
        public static void main(String[] args) {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/spring/application-context.xml");
            UserService u = ctx.getBean("userService");
            u.insert();
    
        }
    }
    

    or something like that.

    However your UserService is lacking its xml configuration or the @Component and depending configuration that spring would actually wire it. You should probably create your local spring configuration file that imports the one from the external jar.

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

Sidebar

Related Questions

I have a project using DynamicJasper to create reports. It works fine so far,
The project works fine in Ruby 1.9.2, but I want to use 1.9.3. This
I have a Django project that works fine with the development server that comes
My project works fine on simulator but wouldn't build on real device after adding:
The REST project works fine, this can be accessed through this address: http://localhost:8525/Device/Login?deviceID=testid&password=a&serialNum=testserial I
My Silverlight 4 WCF RIA Services Project works fine on my dev machine from
I am using org.tuckey.web.filters.urlrewrite.UrlRewriteFilter on my java project.It works fine .My issue is it
I am working on Ruby on Rails. A project which works fine on local
Our flex project, which works fine in its current environment with coldfusion 7 single
i created a simple project with zf and it works fine, but when i

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.