Refactor beens loading.

This commit is contained in:
Paulo Gustavo Veiga
2023-11-19 15:23:45 -08:00
parent a739bb3e0b
commit 479eb6db2c
15 changed files with 35 additions and 85 deletions

View File

@@ -2,11 +2,11 @@ package com.wisemapping.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -17,7 +17,9 @@ import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc
@Configuration
@EnableTransactionManagement
public class AppConfig {
@ComponentScan
@ImportResource("classpath:spring/wisemapping-common.xml")
public class Application {
@Autowired
TransactionManager txManager;

View File

@@ -1,68 +0,0 @@
/*
* Copyright [2022] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.rest;
import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
public class DebugMappingJacksonHttpMessageConverter extends MappingJackson2HttpMessageConverter {
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws JsonHttpMessageNotReadableException {
try {
final byte[] bytes = IOUtils.toByteArray(inputMessage.getBody());
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final WrapHttpInputMessage wrap = new WrapHttpInputMessage(bais, inputMessage.getHeaders());
return super.readInternal(clazz, wrap);
} catch (HttpMessageNotReadableException | IOException e) {
throw new JsonHttpMessageNotReadableException("Request Body could not be read", e);
}
}
}
class WrapHttpInputMessage implements HttpInputMessage {
private final InputStream body;
private final HttpHeaders headers;
WrapHttpInputMessage(InputStream is, HttpHeaders headers) {
this.body = is;
this.headers = headers;
}
@Override
public InputStream getBody() {
return body;
}
@Override
public HttpHeaders getHeaders() {
return headers;
}
}

View File

@@ -23,13 +23,16 @@ import com.wisemapping.model.User;
import com.wisemapping.service.UserService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class UserDetailsService
implements org.springframework.security.core.userdetails.UserDetailsService {
@Autowired
private UserService userService;
private String adminUser;