Tag: spring boot

如何使用Spring Boot Data Rest在同一请求中保存许多对象

我尝试使用POST方法保存一个实体数组,传递一个数组用于rest资源,但是我有一个错误: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of br.com.servtech.almox.model.Item out of START_ARRAY token at [Source: org.apache.catalina.connector.CoyoteInputStream@2af1e451; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of br.com.servtech.almox.model.Item out of START_ARRAY token at [Source: org.apache.catalina.connector.CoyoteInputStream@2af1e451; line: 1, column: 1] at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:228) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE] at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:205) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE] 当我发送一个对象数据时,数据保存得非常好! 我的实体: @Entity public class […]

在LDAP处理期间发生了未分类的exception; 嵌套exception是javax.naming.NamingException

我正在尝试使用带有spring boot安全性的oauth2中的LDAP进行身份validation。 我的配置如下所示 @Configuration @Order(Ordered.HIGHEST_PRECEDENCE) @EnableWebSecurity public class LdapConfiguration extends WebSecurityConfigurerAdapter { private static String url =”ldap://myldapdomain.com:389/OU=Users,OU=Accounts,DC=myldapdomain,DC=com”; @Override protected void configure(HttpSecurity http) throws Exception { http .csrf() .disable() .authorizeRequests() .anyRequest() .authenticated() .and() .httpBasic(); } @Configuration protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) throws Exception { auth .ldapAuthentication() .userSearchFilter(“(uid={0})”) .contextSource().url(url); } […]

在spring boot中使用现有的http服务器作为camel端点

我有一个使用spring boot starter web的spring boot应用程序。 这将创建一个正在运行的Tomcat实例,并设置在端口上运行的http服务器。 在我的骆驼路线中,我想使用这个http服务器作为http请求的组件,但我无法弄清楚如何利用它。 我看到很多配置jetty实例并从中消耗的例子,但是实际上我不会运行两个http服务器吗? 我只想要一个。 我假设http服务器已经自动assembly,因为我可以使用其他弹簧代码(例如RestController)从中消耗它,我也可以看到它在我的spring启动日志中启动。 @Component public class ExampleRoute extends RouteBuilder { @Override public void configure() throws Exception { //@formatter:off from( ) .log( LoggingLevel.INFO, log, “Hello World!” ); //@formatter:on } }

如何在Spring Boot中管理无限进程?

我有一个无限循环的过程: public class MyProcess { public void start() { while (true) { //process } } } 当我开始使用Spring Boot时,我的第一种方法是在应用程序启动后从上下文中获取bean并手动启动该进程: @SpringBootApplication public class MyApplication { public static void main(String[] args) { ApplicationContext applicationContext = SpringApplication.run(MyApplication.class, args); MyProcess myProcess = applicationContext.getBean(MyProcess.class); myProcess.start(); } } 这工作但似乎不是正确的方法,所以我实现了一个CommandLineRunner : @Component public class MyRunner implements CommandLineRunner { @Autowired private MyProcess myProcess; @Override […]

org.glassfish.jersey.server.model.ModelValidationException:应用程序初始化期间应用程序资源模型的validation失败

我正在从链接开发spring boot微服务示例: https : //dzone.com/articles/spring-boot-creating 。 在这个项目中,我只是将父依赖项更新为其最新版本,其他代码文件保持不变。 当我点击http:// localhost:8080 / order?idCustomer = 2&idProduct = 3&amount = 4时遇到以下错误 2016-09-09 11:46:20.888 ERROR 14152 — [nio-8080-exec-1] oaccC[Tomcat].[localhost].[/] : StandardWrapper.Throwable org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. [[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined […]

Spring Boot + Thymeleaf +蒲公英配置不起作用

我正在使用Thymeleaf的Spring Boot,现在我想添加蒲公英数据表,但它不起作用。 这是我的maven依赖项: org.springframework.boot spring-boot-starter-parent 1.2.1.RELEASE org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-websocket org.springframework.boot spring-boot-starter-tomcat provided org.springframework.boot spring-boot-starter-test test com.github.dandelion datatables-thymeleaf 0.10.1 我正在遵循本指南http://dandelion.github.io/dandelion/docs/installation/thymeleaf.html并配置以下bean: @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public FilterRegistrationBean dandelion() { FilterRegistrationBean registrationBean = new FilterRegistrationBean(); registrationBean.setFilter(new DandelionFilter()); registrationBean.addUrlPatterns(“/*”); return registrationBean; } @Bean […]

如何在Spring Boot 1.4中的http请求中为排序参数设置IgnoreCase

我有一个Spring Boot后端运行并接受HTTP请求。 示例: http : //www.myserver.com/devices/ 我正在使用Pageable来处理请求和自动分页和排序,因此我可以使用以下请求: http ://www.myserver.com/devices?sort = name,desc 然而,存在一个问题,即如果区分大小写,则不能获得所需的排序结果(不区分大小写的排序)。 我知道Pageable Sort接受sort属性的两个参数,即sort = name,desc但是在检查调试器时我可以看到pageable的sort orders对象包含ignoreCase属性。 以下是通过REST调用的方法的代码片段: public class DeviceController { @Autowired DeviceViewRepository deviceViewRepository; @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Page getAllDevices(@PageableDefault(page = 0, size = 10, sort= “id”) Pageable pageable) { try { return deviceViewRepository.findAll(pageable); } catch (Exception e){ throw e; } […]

在Spring Config Server中添加环境存储库

我是Spring Boot的新手,所以如果我忽视了一些简单的事情,请原谅。 使用Spring Config Server,您可以通过.yml文件指定您想要使用的环境存储库类型(native,Git等)。 这些环境存储库包含在第三方依赖项中。 我想知道是否可以添加自己的环境存储库,以便您可以连接到数据库以获取配置? 提前谢谢了!

无法使用javaagent为apach httpclient设置spring boot uber jar应用程序

我正在尝试用Bytebuddy编写一个javaagent来拦截apache httpclient请求,我想将这个代理用于spring boot应用程序。 当我从Idea(直接运行main方法)启动测试Spring启动应用程序时,代理工作正常。 但是,当我将应用程序打包到spring boot uber jar并使用java -javaagent:myagent.jar -jar myapplication.jar运行它时,它会抛出以下exception。 onError:org.apache.http.impl.client.AbstractHttpClient java.lang.NoClassDefFoundError: org/apache/http/HttpHost at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.getDeclaredMethods(Class.java:1975) at net.bytebuddy.description.method.MethodList$ForLoadedType.(MethodList.java:106) at net.bytebuddy.description.type.TypeDescription$ForLoadedType.getDeclaredMethods(TypeDescription.java:985) at net.bytebuddy.implementation.MethodDelegation$MethodContainer$ForExplicitMethods.ofStatic(MethodDelegation.java:1037) at net.bytebuddy.implementation.MethodDelegation.to(MethodDelegation.java:247) at net.bytebuddy.implementation.MethodDelegation.to(MethodDelegation.java:226) at com.yiji.dtrace.agent.httpclient4.interceptor.HttpClient4Interceptors$1.transform(HttpClient4Interceptors.java:48) at net.bytebuddy.agent.builder.AgentBuilder$Transformer$Compound.transform(AgentBuilder.java:457) at net.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple$Resolution.apply(AgentBuilder.java:2791) at net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:3081) at sun.instrument.TransformerManager.transform(TransformerManager.java:188) at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at […]

Spring Data REST事件不起作用

我尝试按照以下方式配置spring数据rest事件。所有类都在org.springbootjpa包中 活动: http : //docs.spring.io/spring-data/rest/docs/current/reference/html/#events 以下是我的代码 @SpringBootApplication public class DemoApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run( DemoApplication.class, args); String[] beanNames = context.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } } @Bean GroupEventHandler groupEventHandler() { return new GroupEventHandler(); } } 事件处理程序 @RepositoryEventHandler(UserGroup.class) public class GroupEventHandler { @HandleBeforeSave public void […]