gpt4 book ai didi

java - 无法使用 Maven 部署的依赖项中的类

转载 作者:行者123 更新时间:2023-12-02 01:46:00 26 4
gpt4 key购买 nike

我将依赖项部署到私有(private) Maven 存储库 (JFrog Artifactory)当我要测试时,它会抛出此错误“线程“main”java.lang.NoClassDefFoundError中的异常:无法初始化类org.apache.logging.log4j.util.PropertiesUtil”

这就是我所说的:

AccountManager.getInstance().getAccounts();

在此客户管理器中,我有一个帐户服务,它使用 Spring Boot 中的 RestTemplate 向我的后端 API 发出请求。

堆栈跟踪:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:78)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:135)
at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:102)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:79)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.springframework.http.HttpLogging.<clinit>(HttpLogging.java:45)
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:48)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:44)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:138)
at br.com.toxicnetwork.tooling.account.AccountServiceImpl.<init>(AccountServiceImpl.java:17)
at br.com.toxicnetwork.tooling.account.AccountManager.<init>(AccountManager.java:16)
at br.com.toxicnetwork.tooling.account.AccountManager.getInstance(AccountManager.java:71)
at br.com.toxicnetwork.engine.Main.main(Main.java:8)

客户经理:

public class AccountManager {

private static AccountManager instance;
private AccountService accountService;
private Map<String, Account> cachedAccounts;

private AccountManager() {
accountService = new AccountServiceImpl();
cachedAccounts = new WeakHashMap<>();
}

/**
* Retrieves all cached accounts
*
* @return all accounts created on crm
*/
public Collection<Account> getAccounts() {
return cachedAccounts.values();
}

/**
* Create a new account
*
* @param account account
* @return if the account already exists it returns as null, if not returns a newly account
*/
public Account create(Account account) {
Account createdAccount = accountService.create(account);
cachedAccounts.putIfAbsent(createdAccount.getId(), createdAccount);

return createdAccount;
}

/**
* Gets the account by it's id and deletes
*
* @param id account id
* @return account deleted
*/
public Account delete(String id) {
cachedAccounts.computeIfPresent(id, (presentId, account) -> cachedAccounts.remove(presentId));
return accountService.delete(id);
}

/**
* Get the account by it's id
*
* @param id account id
* @return account found by id
*/
public Account getAccountById(String id) {
return cachedAccounts.containsKey(id) ? cachedAccounts.get(id) : accountService.getAccountById(id);
}

public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}

public static AccountManager getInstance() {
if (instance == null) {
synchronized (AccountManager.class) {
if (instance == null) {
instance = new AccountManager();
}
}
}
return instance;
}
}

账户服务:

public class AccountServiceImpl implements AccountService {

private RestTemplate restTemplate;

public AccountServiceImpl() {
restTemplate = new RestTemplate();
}

@Override
public List<Account> getAccounts(){
ResponseEntity<List<Account>> response = restTemplate.exchange(
Endpoints.USERS.getUrl(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Account>>() {
});

List<Account> accounts = response.getBody();

if(accounts == null){
return null;
}

return accounts;
}

@Override
public Account create(Account account) {
return restTemplate.postForObject(Endpoints.CREATE_USER.getUrl(), account, Account.class);
}

@Override
public Account delete(String id) {
Account toDelete = getAccountById(id);

if(toDelete == null){
return null;
}

restTemplate.delete(Endpoints.DELETE_USER_BY_ID.getUrl(), toDelete.getId(), id);

return toDelete;
}

@Override
public Account getAccountById(String id) {
return restTemplate.getForObject(Endpoints.USERS_BY_ID.getUrl(), Account.class, id);
}
}

最佳答案

Log4j 有一个问题,报告于 https://issues.apache.org/jira/browse/LOG4J2-2129 。使用 2.9,或者使用 2.10 以及该票证中的解决方法,或者使用 2.11.1

关于java - 无法使用 Maven 部署的依赖项中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53654246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com