HttpMessageConverter
в конфиг Spring
:...
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(stringConverter());
converters.add(mappingJackson2HttpMessageConverter());
converters.add(excelConverter());
}
...
}
...
@Bean
public ResourceHttpMessageConverter excelConverter() {
final ResourceHttpMessageConverter converter = new ResourceHttpMessageConverter();
converter.setSupportedMediaTypes(
List.of(new MediaType("application", "vnd.ms-excel"))
);
return converter;
}
....
return ResponseEntity
.ok()
.headers(headers)
.contentLength(fileCont.length)
.contentType(new MediaType("application", "vnd.ms-excel"))
.body(new InputStreamResource(in));
}
}
@PersistenceContext(unitName = Constants.ADM_ENTITY_MANAGER_FACTORY_NAME)
private EntityManager em;
@Bean(name = Constants.ADM_ENTITY_MANAGER_FACTORY_NAME, destroyMethod = "")
public LocalContainerEntityManagerFactoryBean admEntityManagerFactory() throws NamingException {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSourceAdm());
em.setPackagesToScan(admPackagesToScan);
em.setPersistenceUnitName(Constants.ADM_ENTITY_MANAGER_FACTORY_NAME);
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(hibernatePropertiesAdm());
return em;
}
ServiceProperties
:jaxbContext = JAXBContext.newInstance(PACKAGE_WITH_JAXB_OBJECTS + ":" + PACKAGE_WITH_JAXB_OBJECTS_2);
package-info.java
с основного пакета. Файл имеет такое содержимое:@javax.xml.bind.annotation.XmlSchema(namespace = "http://firma.ru/schema/v6_1/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package ru.my-firm.app.my-project.jaxbobjects;
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(SpringConfig.class, WebConfig.class);
context.setServletContext(servletContext);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
FilterRegistration.Dynamic filterRegistration = servletContext
.addFilter("characterEncodingFilter", characterEncodingFilter);
filterRegistration.addMappingForUrlPatterns(null, false, "/*");
}
}
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
FilterRegistration.Dynamic filterRegistration = servletContext
.addFilter("characterEncodingFilter", characterEncodingFilter);
filterRegistration.addMappingForUrlPatterns(null, false, "/*");
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
ArrayList<T>
, то лучше использовать переменные типа List<T>
.ArrayList<String> name = new ArrayList(Arrays.asList(1,2,3));
for (String s : name) {
System.out.println(s);
}