- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
package baseDao;
public interface BaseDao {
public void create(Object obj);
public void delete(Object obj);
public void update(Object obj);
public void get(Object obj);
}
package baseDao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class BaseDaoImpl implements BaseDao {
@Autowired
private SessionFactory usermanagementSessionFactory;
private Session session = usermanagementSessionFactory.getCurrentSession();
/*-----------------To save an object--------------*/
public void create(Object obj){
session.save(obj);
}
/*-----------------To delete an object--------------*/
public void delete(Object obj){
session.delete(obj);
}
/*-----------------To update an object--------------*/
public void update(Object obj){
session.update(obj);
}
/*-----------------To find/Get an object--------------*/
public void get(Object obj){
}
protected SessionFactory getUsermanagementSessionFactory() {
return usermanagementSessionFactory;
}
protected void setUsermanagementSessionFactory(
SessionFactory usermanagementSessionFactory) {
this.usermanagementSessionFactory = usermanagementSessionFactory;
}
}
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<util:properties id="usermanagementHibernateProperties" location="classpath:usermanagement-hibernate.properties" />
<bean id="usermanagementSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="usermanagementDataSource" />
<property name="configLocation" value="classpath:hibernate.cfg.usermanagement.xml" />
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="hibernateProperties" ref="usermanagementHibernateProperties" />
</bean>
<jee:jndi-lookup id="usermanagementDataSource" jndi-name="java:usermanagementDS" />
<bean id="city" class="com.ecom.data.entities.user.City"/>
<bean id="state" class="com.ecom.data.entities.user.State"/>
<bean id="country" class="com.ecom.data.entities.user.Country"/>
<bean id="pincodes" class="com.ecom.data.entities.user.Pincodes"/>
<bean id="notification" class="com.ecom.data.entities.notification.Notifications"/>
<bean id="notification_types" class="com.ecom.data.entities.notification.Notification_Types"/>
<bean id="transactions" class="com.ecom.data.entities.transaction.Transactions"/>
<bean id="address" class="com.ecom.data.entities.user.Address"/>
<bean id="user_master" class="com.ecom.data.entities.user.User_Master"/>
<bean id="notification_channels" class="com.ecom.data.entities.notification.Notification_Channels"/>
<bean id="notification_time" class="com.ecom.data.entities.notification.Notification_Time"/>
<bean id="prefilled_response" class="com.ecom.data.entities.product.Prefilled_Response"/>
<bean id="payment_options" class="com.ecom.data.entities.transaction.Payment_Options"/>
<bean id="catagory" class="com.ecom.data.entities.product.Catagory"/>
<bean id="vendor" class="com.ecom.data.entities.product.Vendor"/>
<bean id="requester" class="com.ecom.data.entities.product.Requester"/>
<bean id="requirement_type" class="com.ecom.data.entities.product.Requirement_type"/>
<bean id="discount_offer_type" class="com.ecom.data.entities.product.Discount_Offer_Type"/>
<bean id="discount_offers" class="com.ecom.data.entities.product.Discount_Offers"/>
<bean id="requirements" class="com.ecom.data.entities.product.Requirements"/>
<bean id="product_catalog" class="com.ecom.data.entities.product.Product_Catalog"/>
<bean id="product_catalog_vendor" class="com.ecom.data.entities.product.Product_Catalog_Vendor"/>
<bean id="product_vendor_payment_option_location" class="com.ecom.data.entities.product.PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION"/>
<bean id="baseDaoImpl" abstract="true" class="baseDao.BaseDaoImpl"> </bean>
<bean id="pincodeDao" parent="baseDaoImpl" class="com.ecom.data.access.user.PincodeDao"> </bean>
</beans>
package com.ecom.data.access.user;
import junit.framework.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ecom.data.entities.user.Pincodes;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext-usermanagement-dao.xml",
"/applicationContext-usermanagement-dao-test.xml" })
public class PiccodeTest extends AbstractTransactionalJUnit4SpringContextTests {
@BeforeClass
public static void setup(){}
@Test
public void pincodeTest(){
PincodeDao pinDao = new PincodeDao(); // object of dao class to call the create method
pinDao.save();
}
}
______________________________________________________________________
when i run this code with junit with maven it gives the error
-------------------->
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1f2edd2] to prepare test instance [com.ecom.data.access.user.PiccodeTest@1dbb27d]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pincodeDao' defined in class path resource [applicationContext-usermanagement-dao.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ecom.data.access.user.PincodeDao]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:96)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:44)
at org.springframework.test.context.TestContext.buildApplicationContext(TestContext.java:198)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:233)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:126)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:85)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:95)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:139)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ecom.data.access.user.PincodeDao]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
... 30 more
Caused by: java.lang.NullPointerException
at baseDao.BaseDaoImpl.<init>(BaseDaoImpl.java:11)
at com.ecom.data.access.user.PincodeDao.<init>(PincodeDao.java:7)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 32 more
最佳答案
将 session 初始化移动到下面的方法
@PostConstruct
public void init(){
session = usermanagementSessionFactory.getCurrentSession();
}
关于spring - 无法实例化 bean : Constructor threw exception; nested exception is java. lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16561323/
我的 iPad 应用程序一直在日志中显示此消息...... : ImageIO: CreateMetadataFromXMPBufferInternal Threw error #203 (Dupl
我正在使用 sinon.JS 编写简单的单元测试。被测试的代码有一些类型检查,这会抛出 TypeError: Tx = class Tx { constructor(date) {
我正在使用 args4j 来解析提供给我的程序的参数。 这是我定义 2 个日期类型参数的代码。该处理程序仅解析给定的日期,如果日期格式错误,则抛出 CommandLineException。 @Opt
回归。升级插件后,我的应用程序不再启动。 这是我的 flutter 规范: Flutter 已在稳定 channel 上保持最新状态 Flutter 3.0.2 • channel 稳定 • http
我开发 WPF Prism 6 MVVM 多模块应用程序。直到今天一切正常。但是今天早上我决定清理并重建我的应用程序。在清理和重建后,我的应用程序运行时出现以下错误: PresentationFram
我正在我的 Java EE Maven 项目中使用这个库:https://github.com/bertrandmartel/speed-test-lib 我收到以下异常 java.lang.Clas
我使用假客户端微服务并收到以下错误 - $ mvn spring-boot:run [INFO] Scanning for projects... [INFO] [INFO] ------------
我已经创建了一个调用我的不同模式的服务。所以我有一个模态调用“Confirm Modal”,它可以接受 3 个参数:一个确认函数、一个拒绝函数和一个主体。这是以下模式: export class Co
我正在尝试访问静态列表的值。但是,当我尝试这样做时,会抛出此异常。 System.TypeInitializationException: The type initializer for 'Tips
我将 Spring MVC 与 Spring Boot 和 Thymeleaf 结合使用。我有返回 Thymeleaf 模板名称的普通 Controller 和用 @RepsonseBody 注释的
Objective: {objective 0x7fb7a49de030: + *0x7fb7a4d254b0.negError{id: 1392} + *UIButton:0x7fb7a4b877
我有一个用户报告了这个异常。我在这里和其他地方的研究表明这是一个静态构造函数错误。有关的类包含许多已初始化的静态字段。我认为它是其中之一,但我不确定如何找到它。该建议似乎是在静态构造函数中包含一个 t
我在调用 WCF 服务时收到如下 FaultException: 2012-04-02 16:26:00.3593|Error|System.ServiceModel.FaultException`1
我执行了一个 spark 程序,在该程序中,我使用客户框架将 Drools 规则应用于事实对象。我在 Flatmap 函数中调用了这个自定义框架,并且规则已成功执行,但在收集结果后我看到了以下异常。
我在执行项目时遇到上述错误。当我以正常方式执行它时,它运行良好,没有抛出任何错误。但是当我尝试通过 oozie 将其作为 java 操作调用来运行相同的程序时,它会抛出以下异常 Failing Ooz
我正在使用 JAX-RS jersey ExceptionMapper,我想知道是否有办法在方法 toResponse() 内部知道哪个方法(来自 API)抛出了异常。 示例(伪代码) @javax.
我是 Spring 新手,我正在尝试执行此应用程序,但遇到了这样的异常 SEVERE: Servlet [spring] in web application [/loginDB] threw loa
我是 android 和 xamarin 的新手。最近我根据 xamrarin 示例 TaskyPortable 创建了一个 android 应用程序。问题是每当执行以下代码时都会抛出错误。
我遇到了这个错误,我不知道出了什么问题我只是想检查用户名和密码,然后进入一个显示是否登录的页面 package cse; import java.io.IOException; import java
在 eclipse Juno 上的 Tomcat 6.0.26 中部署我的应用程序时出现以下错误。我将 struts 用于 Web 内容,将 spring 用于 ORM。 我已尝试清理和构建工作区。
我是一名优秀的程序员,十分优秀!