#Bean Definition
1 messages ยท Page 1 of 1 (latest)
<@&1004656351647117403> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
The action it requires is
Consider defining a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' in your configuration.
which I have
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
And I auto wire it into my class
@Autowired
private PasswordEncoder passwordEncoder;
Hi, have you checked if your imports are both the same?
and that the class that exposes ur bean is annotated as @Configuration?
Yup both the same also I used it before and it worked fine just haevn't been on the projecty for like 3 4 weeks
Its my secuirty config
@EnableWebSecurity
public class SecurityConfiguration {
EnableWebSecuirty auto adds Confuration
The full error is this
Description:
Field passwordEncoder in com.techtanium.backend.auth.AuthService required a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' in your configuration.
Try annotating your SecurityConfiguration with @Configuration
That seems to have fixed it but broken every single one of my unit tests
interesting
Everything returning 404 NOT FOUND
not 401?
are your tests annotated as springboottest?
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class UserControllerTest {
Correct
and if you do a manual test? does it work as expected?
Ignore that sorry
np ๐
It does work ๐
can you post the controller and test method?
Just one of them?
one of the ones that are not working
Yeah okay one sec
Let me get back to you actually as I am facing so many other issues now ๐
okay, good luck on that ๐ make sure to ping me @lucid tree like this. otherwise i might not notice
Yes will do thank you for the help so far!
@Test
public void whenPostRegister_emailContainsCapitals_returnUserWithoutCapitals() {
User user = createValidUser();
user.setEmail("[email protected]");
User inDB = userService.save(user);
authenticate("test-username");
ResponseEntity<Map<String, Object>> response = login(new ParameterizedTypeReference<>() {});
Map<String, Object> body = response.getBody();
String email = (String) body.get("email");
assertThat(email).isEqualTo("[email protected]");
}
private void authenticate(String username) {
testRestTemplate.getRestTemplate()
.getInterceptors().add(new BasicAuthenticationInterceptor(username, "P4ssword"));
}
public <T> ResponseEntity<T> login(ParameterizedTypeReference<T> responseType) {
return testRestTemplate.exchange(API_1_LOGIN, HttpMethod.POST,null, responseType);
}
@RestController
public class LoginController {
@Autowired
AuthService authService;
@PostMapping("/api/1.0/login")
AuthResponse handleAuthentication(@RequestBody Credentials credentials) throws AuthException {
return authService.authenticate(credentials);
}
}
@lucid tree So I managed to figure out the other issues and solved most of it now just this problem left I am getting a 415 but confused as the media type is text and its the same issue for all the other tests in this class had a look at it for awhile now and even debugging it cant see the problem
This fixed the other issue also reading into it I seem to have always needed this so surprised it worked without it unless I some how got rid of it at some point and forgot
i mean spring boot comes with most of the stuff autoconfigured so maybe it worked, just not with your implementation ๐ i think i cant help you with the 415 atm since im only on phone now.