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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.transaction.TransactionManager; import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; 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.HandlerExceptionResolver;
import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@ -17,7 +17,9 @@ import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc @EnableWebMvc
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
public class AppConfig { @ComponentScan
@ImportResource("classpath:spring/wisemapping-common.xml")
public class Application {
@Autowired @Autowired
TransactionManager txManager; 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 com.wisemapping.service.UserService;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.dao.DataAccessException;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class UserDetailsService public class UserDetailsService
implements org.springframework.security.core.userdetails.UserDetailsService { implements org.springframework.security.core.userdetails.UserDetailsService {
@Autowired
private UserService userService; private UserService userService;
private String adminUser; private String adminUser;

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">-->
<!-- <property name="defaultEncoding" value="UTF-8"/>-->
<!-- <property name="basenames">-->
<!-- <list>-->
<!-- <value>messages</value>-->
<!-- </list>-->
<!-- </property>-->
<!-- </bean>-->
<import resource="wisemapping-datasource.xml"/>
<import resource="wisemapping-dao.xml"/>
<import resource="wisemapping-service.xml"/>
<import resource="wisemapping-servlet.xml"/>
</beans>

View File

@ -13,11 +13,10 @@
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.wisemapping.rest"/> <context:component-scan base-package="com.wisemapping.rest"/>
<context:annotation-config/>
<mvc:annotation-driven> <mvc:annotation-driven>
<mvc:message-converters> <mvc:message-converters>
<bean class="com.wisemapping.rest.DebugMappingJacksonHttpMessageConverter"/> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/> <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
</mvc:message-converters> </mvc:message-converters>
</mvc:annotation-driven> </mvc:annotation-driven>

View File

@ -33,5 +33,5 @@
</property> </property>
</bean> </bean>
<import resource="wisemapping-security-${security.type}.xml"/> <import resource="wisemapping-security-${security.type:db}.xml"/>
</beans> </beans>

View File

@ -12,8 +12,6 @@
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.wisemapping"/> <context:component-scan base-package="com.wisemapping"/>
<context:annotation-config/>
<mvc:annotation-driven/>
<context:property-placeholder location="/WEB-INF/app.properties" ignore-unresolvable="true"/> <context:property-placeholder location="/WEB-INF/app.properties" ignore-unresolvable="true"/>
<!-- Interceptors Registration --> <!-- Interceptors Registration -->

View File

@ -24,10 +24,7 @@
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value> <param-value>
/WEB-INF/wisemapping-datasource.xml classpath:spring/wisemapping-common.xml
/WEB-INF/wisemapping-dao.xml
/WEB-INF/wisemapping-service.xml
/WEB-INF/wisemapping-servlet.xml
</param-value> </param-value>
</context-param> </context-param>
@ -35,8 +32,7 @@
<param-name>contextInitializerClasses</param-name> <param-name>contextInitializerClasses</param-name>
<param-value>com.wisemapping.webmvc.ApplicationContextInitializer</param-value> <param-value>com.wisemapping.webmvc.ApplicationContextInitializer</param-value>
</context-param> </context-param>
<!-- <!--
- Loads the root application context of this web app at startup. - Loads the root application context of this web app at startup.
- The application context is then available via - The application context is then available via
@ -91,7 +87,7 @@
<init-param> <init-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value> <param-value>
/WEB-INF/wisemapping-servlet.xml classpath:spring/wisemapping-servlet.xml
</param-value> </param-value>
</init-param> </init-param>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
@ -103,7 +99,7 @@
<init-param> <init-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value> <param-value>
/WEB-INF/wisemapping-rest.xml classpath:spring/wisemapping-rest.xml
</param-value> </param-value>
</init-param> </init-param>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>