第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么我的employeeRepository沒(méi)法成功注入???

package?com.oracle.repository;

import?org.junit.After;
import?org.junit.Before;
import?org.junit.Test;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.context.ApplicationContext;
import?org.springframework.context.support.ClassPathXmlApplicationContext;

import?com.oracle.domain.Employee;

public?class?TestRepository?{
	private?ApplicationContext?ac?=?null;
	private?EmployeeRepository?employeeRepository=null;
	@Before
	public?void?setup(){
		ac?=?new?ClassPathXmlApplicationContext("beans.xml");
		employeeRepository?=?(EmployeeRepository)?ac.getBean("employeeRepository");
		System.out.println("setup");
	}
	@After
	public?void?teardown(){
		ac?=?null;
		System.out.println("teardown");
	}
	@Test
	public?void?testFindByName(){
		Employee?emp?=?employeeRepository.findByName("cyf2");
		System.out.println(emp);
	}

}

<?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:context="http://www.springframework.org/schema/context" ?

? ? ?xsi:schemaLocation="http://www.springframework.org/schema/beans?

? ? ?http://www.springframework.org/schema/beans/spring-beans.xsd?

? ? ?http://www.springframework.org/schema/context?

? ? ?http://www.springframework.org/schema/context/spring-context.xsd">?

<!-- 1 配置數(shù)據(jù)源 -->

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="com.mysql.jdbc.Driver"/>

<property name="username" value="root"/>

<property name="password" value="root"/>

<property name="url" value="jdbc:mysql://localhost:3306/scott"/>

</bean>

<!-- <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">

<property name="dataSource" ref="dataSource" />

</bean> -->

<!--配置EntityManagerFactory ?-->

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="jpaVendorAdapter">

<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

</property>

<property name="packagesToScan" value="com.oracle" />

<property name="jpaProperties">

<props>

<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>

<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>

<prop key="hibernate.show_sql">true</prop>

<prop key="hibernate.format_sql">true</prop>

<prop key="hibernate.hbm2ddl.auto">update</prop>

</props>

</property>

</bean>

</beans>

package com.oracle.repository;


import org.springframework.data.repository.Repository;

import org.springframework.stereotype.Component;

import org.springframework.stereotype.Service;


import com.oracle.domain.Employee;

?

public interface EmployeeRepository extends Repository<Employee, Integer>{

public Employee findByName(String name);

}


正在回答

5 回答

ac?=?new?ClassPathXmlApplicationContext("beans.xml");

這一行代碼中,你需要改成

ac?=?new?ClassPathXmlApplicationContext("beans-new.xml");

后面換了配置文件的

0 回復(fù) 有任何疑惑可以回復(fù)我~

請(qǐng)?jiān)囍鴱南旅鎺追矫娼鉀Q問(wèn)題:

1、是否將其EmployeeRepository配置到bean配置文件中

2、測(cè)試類中是否加載正確的bean配置文件

3、獲取的bean的時(shí)候,是否為正確的bean名稱

0 回復(fù) 有任何疑惑可以回復(fù)我~

擦,是不是找到了你加載的beans.xml文件名稱錯(cuò)了

0 回復(fù) 有任何疑惑可以回復(fù)我~

這個(gè)也不行,有沒(méi)有誰(shuí)知道其他方法嗎?謝謝

0 回復(fù) 有任何疑惑可以回復(fù)我~

試試? ac.getBean(EmployeeRepository.class)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么我的employeeRepository沒(méi)法成功注入???

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)