Неоднозначное отображение. Невозможно сопоставить ***; уже сопоставлен метод bean-компонента ***JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Неоднозначное отображение. Невозможно сопоставить ***; уже сопоставлен метод bean-компонента ***

Сообщение Anonymous »

Итак, спустя много лет мы наконец обновили нашу среду Spring до последней версии, и это включает в себя некоторые проблемы, которые мне удалось устранить. Но этого я, кажется, не могу понять.
У нас есть LoginController, который содержит различные сопоставления, такие как LoginRedirect.do, ChangePassword.Do и т. д. Но по какой-то причине я продолжаю получать это сообщение об ошибке при попытке развернуть файл войны в tomcat:

Вызвано: java.lang.IllegalStateException: неоднозначное сопоставление. Невозможно сопоставить метод 'customUserDetailsService2'
com.test.controller.LoginController#loginRedirect(ModelMap)
с {GET [/login/LoginRedirect.do]}: уже существует метод bean-компонента 'loginController'
com.test.controller.LoginController#loginRedirect(ModelMap) сопоставлен.

У меня нет других контроллеров, которые имеют такие сопоставления, но, похоже, это вызвано нашим bean-компонентом customUserDetailsService2. В нашем ApplicationContext-security.xml есть следующее: И контроллеры входа выглядят так:

Код: Выделить всё

package com.test.controller;

import com.test.dao.datasnap.ILoginDAO;
import com.test.dao.datasnap.IPublicMethodsDAO;
import com.test.dao.datasnap.IUtilDAO;
import com.test.exception.DataSnapException;
import com.test.model.BasicResult;
import com.test.model.LoginResponse;
import com.test.model.PDCUser;
import com.test.security.CustomUser;
import com.test.security.CustomUserDetailsService;
import com.test.security.Module;
import com.test.translations.UITranslationCache;
import com.test.util.Util;
import jakarta.servlet.http.HttpServletRequest;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Controller
@Scope("request")
@RequestMapping("login")
public class LoginController implements CustomUserDetailsService {

/*
* Autowired DAO for Login
*/
@Autowired
private ILoginDAO dataDAO;

@Autowired
private IUtilDAO utilDAO;

@Autowired
private IPublicMethodsDAO methodsDAO;

/*
* Gets the current logged in user.
*/
@GetMapping(value="/GetUserName.do")
public String printUser(ModelMap modelMap) {

String name = Util.getUserName(); //get logged in username
modelMap.put("data", name);
return "ajax/json/dataresponse";
}

//from the CustomUserDetailsService interface
public UserDetails loadUserByUsernamePasswordAuthenticationToken(UsernamePasswordAuthenticationToken authentication)
throws UsernameNotFoundException, DataAccessException {

/*
* Use the DAO to get the data we want.  This is something we really want to delegate so that we can keep our controller code as small
* as possible.
*/

try {

String username = authentication.getName();
if (((username == null) || "".equals(username))) {
throw new BadCredentialsException(UITranslationCache.GetUITranslation(16877, Util.GetCompanyLanguage(), "Username and/or password are not correct."));
}

LoginResponse returnObject = dataDAO.loginToPDC(authentication);
PDCUser pdcUser = (PDCUser) returnObject.getDataObject();

List authList = new ArrayList(2);

/*
* based on the settings retrieved from DataSnap, we set the appropriate authorities for the user
*/
if (pdcUser != null && pdcUser.getModules() != null) {
Iterator itr = pdcUser.getModules().iterator();
while(itr.hasNext()) {
Module module = itr.next();
if (module.getGrantedauthority() != null) {
authList.add(new SimpleGrantedAuthority(module.getGrantedauthority()));
}
}
}

UserDetails user = null;
boolean enabled = true;
user = new CustomUser(
pdcUser.getUsername(),
pdcUser.getManNr(),
pdcUser.getPassword(),
enabled,
authList,
returnObject.getSessionId(),
pdcUser.getModules(),
pdcUser.getLanguageCode(),
pdcUser.getRememberMe(),
pdcUser.getPasswordExpired());

return user;
} catch (DataSnapException e) {
throw new AuthenticationServiceException(e.getMessage());
} catch (AuthenticationException e) {
throw e;
} catch (Exception e)   {
e.printStackTrace();
}
return null;
}

@ResponseStatus(value=HttpStatus.FORBIDDEN)
@GetMapping(value = "/accessdenied.do")
public ModelAndView accessDenied(ModelMap modelmap) {

Authentication auth = SecurityContextHolder.getContext().getAuthentication();
List modules = Util.getModules();

modelmap.put("modules", modules);
modelmap.put("username", auth.getName());

return new ModelAndView("accessdenied", modelmap); // logical view name ->  accessdenied.jsp

}

@ResponseStatus(value=HttpStatus.UNAUTHORIZED)
@GetMapping(value ="/LoginRedirect.do")
public String loginRedirect(ModelMap modelmap) throws JSONException{

JSONObject jsonObject = new JSONObject();
jsonObject.put("success", false);
jsonObject.put("message", UITranslationCache.GetUITranslation(16878, Util.GetCompanyLanguage(), "User not authorized to view this page"));

modelmap.put("data", jsonObject);

return "ajax/json/dataresponse";
}

@GetMapping(value ="/LogoutAjax.do")
public String logoutAjax(ModelMap modelmap) throws JSONException{

JSONObject jsonObject = new JSONObject();
jsonObject.put("success", true);
jsonObject.put("message", UITranslationCache.GetUITranslation(16879, Util.GetCompanyLanguage(), "User was succesfully logged out"));

modelmap.put("data", jsonObject);

return "ajax/json/dataresponse";
}

@GetMapping(value ="/ChangePassword.do")
public String changePassword(@RequestParam(required = true, value = "oldpw") String oldpw,
@RequestParam(required = true, value = "newpw") String newpw,
ModelMap modelMap) throws DataSnapException {

BasicResult result = utilDAO.ChangePassword(oldpw, newpw);

modelMap.put("data", result.getResult());

return "ajax/json/dataresponse";
}

}
Похоже, что LoginController сам по себе сопоставляет различные методы до того, как customUserDetailsService2 внесет изменения для этого. Но раньше это работало, поэтому я немного не понимаю, почему это не работает сейчас.

Подробнее здесь: https://stackoverflow.com/questions/784 ... hod-mapped
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»