internetitem / spring-boot-cxf-jaxrs

Spring Boot CXF Integration
MIT License
10 stars 3 forks source link

How to add the spring-boot-cxf-jaxrs to application #1

Open michaldo opened 9 years ago

michaldo commented 9 years ago

I follow Spring Boot guide. I reached chapter 11.4 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started-first-application-run Everything is OK. Then I add dependcy to spring-boot-cxf-jaxrs:1.1 I got exceptions like ava.lang.IllegalStateException: Error processing condition on com.internetitem.spring.cxf.CxfConfiguration.jsonProvider at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58) at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:190) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) at cfx.Example.main(Example.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: @ConditionalOnMissingBean annotations must specify at least one bean (type, name or annotation) at org.springframework.util.Assert.isTrue(Assert.java:65) at org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanSearchSpec.(OnBeanCondition.java:232) at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:93) at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45) ... 22 common frames omitted

What is wrong? Could you provide working demo how to use spring-boot-cxf-jaxrs?

abatkin commented 9 years ago

I just tried to reproduce the above problem but I am unable. I have tested with Spring Boot 1.2.0 (the version I originally developed with), 1.2.5 (latest released version) and 1.3.0.BUILD-SNAPSHOT (latest code). What version of Spring Boot and Spring are you running with?

There is a working example (which hasn't been updated in a while, but should work) here.

michaldo commented 9 years ago

My example is here:https://github.com/michaldo/issue1 Command mvn spring-boot:run fails

michaldo commented 9 years ago

Unfortunately, your working example doesn't work on my computer. I cloned git repo, call mvn spring-boot:run, I get exceptions like

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'RecipientConfig' in string value "${RecipientConfig}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)

abatkin commented 9 years ago

To get GitHook to work, you need to pass some arguments on the command line or else provide an application.properties file (see the project's README.md for more information).

As for your project, you are missing the CXF dependency in your pom.xml:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxrs</artifactId>
    <version>3.0.2</version>
</dependency>

Once you do that you will get a different error ("org.apache.cxf.service.factory.ServiceConstructionException: No resource classes found") which is informing you that you haven't declared any JAX-RS Resource beans. In other words, you are trying to use CXF integration but you aren't using CXF.

The Example service is using Spring's built-in RestController support. Which is great - and can be used in lieu if (or inconjunction with) JAX-RS/CXF - but is a different beast. In fact, if you just remove the spring-boot-cxf-jaxrs dependency from your project, it will work fine.

michaldo commented 9 years ago

Thank you, now I started my application. I think you can increase your documentation.

  1. if spring-boot-cxf-jaxrs needs cxf-rt-frontend-jaxrs, then there should be a maven dependency or documentation note
  2. Minimal demo application (hello world) starting out of the box will be helpful
  3. Line @ImportResource({"classpath:META-INF/cxf/cxf.xml"}) is not clear to me. I don't have cfx.xml it is OK or not? How it relates to default CXF configuration which is expected in /WEB-INF/classes?