0
私はリポジトリとして以下のクラスUserAuthorityRepository
ありますクラス<T>を豆としてどのように注入するのですか?
@Repository
public class UserAuthorityRepository extends BaseRepository<UserAuthority, Long> implements IUserAuthorityRepository {
public UserAuthorityRepository(Class<UserAuthority> domainClass, EntityManager em) {
super(domainClass, em);
}
}
そしてUserAuthorityService
に私が持っている:
@Service
public class UserAuthorityService extends BaseService<UserAuthority, Long> implements IUserAuthorityService {
private static final Logger LOGGER = LoggerFactory.getLogger(UserAuthorityService.class);
@Autowired
private IUserAuthorityRepository userAuthorityRepo;
public UserAuthorityService() {
super();
LOGGER.info("UserAuthorityService Has Been Created");
}
@Bean
@Override
public Class<UserAuthority> getDomain() {
return UserAuthority.class;
}
@Override
public IBaseRepository<UserAuthority, Long> getRepository() {
return userAuthorityRepo;
}
}
をしかし、私のアプリケーションは、次のように起動時に例外を取得します。
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.bia2hd.dao.impl.UserAuthorityRepository required a bean of type 'java.lang.Class' that could not be found.
Action:
Consider defining a bean of type 'java.lang.Class' in your configuration.
の可能性のある重複した[Beanのプロパティを春にクラス値を設定する方法?](http://stackoverflow.com/questions/5834311/how-to-set-class- value-to-spring-bean-property) –
@JoeCありがとうございます。しかし、xml設定はありません。すべての注釈です。 – Khodabakhsh
ここで潜在的に愚かな質問...しかし、なぜこのコンテキストで 'クラス'を注入する必要がありますか?あなたのコンストラクタ引数の唯一の正当な値は 'UserAuthority.class'です。なぜなら、注入コンストラクタに代わって明示的にスーパーコンストラクタ呼び出しを設定しないと、' EntityManager'だけを注入する必要があります。 –