The jar of this class file belongs to container 'JUnit 4' which does not allow ...

本文详细解析了在使用JUnit4进行Hibernate环境测试时遇到的错误,并分享了解决方案。通过对比测试方法前后代码,强调了public修饰符的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The jar of this class file belongs to container 'JUnit 4' which does not allow modification to source attachments on its entries.

代码:

	@Test
	void function1(){
		//1,加载配置文件
		Configuration configuration = new Configuration().configure();
		
		//2,创建sessionFactory
		SessionFactory sessionFactory = configuration.buildSessionFactory();
		
		//3,创建session
		Session session = sessionFactory.openSession();
		
		//4,开启事务
		Transaction transaction = session.beginTransaction();
		
		//5,执行事务
		Customer customer = new Customer();
		customer.setCust_name("Test");
		session.save(customer);
		transaction.commit();
		
		//6,关闭资源
		session.close();
		sessionFactory.close();
	}

 

以上是我在用JUnit4 进行Hibernate环境测试时候报的错误,网上搜了一下,各种五花八门的回答,但是感觉都跟我的不沾边,后边检查了一下,发现原来是我的测试方法没有public..加上public就好了

	@Test
	public void function1(){
		//1,加载配置文件
		Configuration configuration = new Configuration().configure();
		
		//2,创建sessionFactory
		SessionFactory sessionFactory = configuration.buildSessionFactory();
		
		//3,创建session
		Session session = sessionFactory.openSession();
		
		//4,开启事务
		Transaction transaction = session.beginTransaction();
		
		//5,执行事务
		Customer customer = new Customer();
		customer.setCust_name("Test");
		session.save(customer);
		transaction.commit();
		
		//6,关闭资源
		session.close();
		sessionFactory.close();
	}

想知道为什么要加public?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值