I´m working on this Vaadin Tutorial series.
https://www.youtube.com/watch?v=k-DxZ1reIdM&list=PLcRrh9hGNallPtT2VbUAsrWqvkQ-XE22h&index=11
Text Version: https://vaadin.com/learn/tutorials/modern-web-apps-with-spring-boot-and-vaadin/vaadin-form-data-binding-and-validation?
I´m trying to use Binding but I get the following error in my Terminal:
2020-11-22 09:11:11.012 INFO 38103 --- [nio-8080-exec-2] c.vaadin.flow.spring.SpringInstantiator : The number of beans implementing 'I18NProvider' is 0. Cannot use Spring beans for I18N, falling back to the default behavior
2020-11-22 09:11:11.373 INFO 38103 --- [nio-8080-exec-2] com.vaadin.validator.BeanValidator : A JSR-303 bean validation implementation not found on the classpath or could not be initialized. BeanValidator cannot be used.
more below the next:
Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
How do I add a Bean Validation provider? I´m working with vaadin as a maven project same as in the tutorial.
Solved by adding the following dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Related
i add spring boot project as dependency in spring mvc project , application can run successfully but when i call service i faced below error
Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to read candidate component class: nested exception is
org.springframework.core.annotation.AnnotationConfigurationException:
Attribute 'proxyBeanMethods' in annotation
[org.springframework.boot.SpringBootConfiguration] is declared as an
#AliasFor nonexistent attribute 'proxyBeanMethods' in annotation
[org.springframework.context.annotation.Configuration].; nested
exception is java.lang.NoSuchMethodException:
org.springframework.context.annotation.Configuration.proxyBeanMethods()
Attribute 'proxyBeanMethods' in annotation
[org.springframework.boot.SpringBootConfiguration] is declared as an
#AliasFor nonexistent attribute 'proxyBeanMethods' in annotation
[org.springframework.context.annotation.Configuration].; nested
exception is java.lang.NoSuchMethodException:
org.springframework.context.annotation.Configuration.proxyBeanMethods()
It mainly complains about your #Configuration does not have an attribute called proxyBeanMethods. Checking from the javadoc , this attribute is added since Spring 5.2.
Most probably it is because you are messing up the spring version with your spring-boot version. Your spring version is too old (before 5.2) such that the above attribute of the #Configuration is not defined.
You should use the spring framework which the version is defined by the spring-boot version that you use . Show me the pom.xml and I can help to check which <dependency> causes such version mismatch. Thanks.
I'm trying to load the JAXB modules as OSGi bundles with Java 11 and Apache Felix using a POM-first approach (the OSGi meta data gets generated).
First I tried with:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-osgi</artifactId>
<version>2.3.3</version>
</dependency>
but this gives me the following runtime exception:
SCHWERWIEGEND: Implementation of JAXB-API has not been found on module path or classpath.
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
It might be related to the following issue, but I'm not sure: https://github.com/eclipse-ee4j/jaxb-api/issues/78
So I tried with v3.0.0 but now one of my annotation processory which generate an XML document using JAXB, fails:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project my-module: Compilation failure
Implementation of JAXB-API has not been found on module path or classpath.
I noticed that jaxb-osgi-3.0.0.jar does not provide the com.sun.xml.bind package anymore
I also tried to migrate from javax.xml.bind to jakarta.xml.bind, but the Maven Plugins, which generate POJO classes from XSDs, don't seem to be ready yet at the time of writing (neither org.jvnet.jaxb2.maven2:maven-jaxb2-plugin nor org.codehaus.mojo:jaxb2-maven-plugin).
My questions:
Where can I get the com.sun.xml.bind from?
How do the jaxb-osgi and jaxb-impl modules relate?
How is this all supposed to work?
How can I proceed?
Update - background information
I have the following setup based on the Extender Pattern:
core extender module M:
provides some JAXB classes
a BundleTracker to unmarshal XML documents from a META-INF sub-directory of some bundles X, Y, Z
an abstract custom annotation processor to marshal the XML documents
extension modules A, B, C:
provide additional JAXB classes (generated from XSDs)
extensions are registered using Declarative Services
custom annotations
annotation processors to convert the annotation attributes to JAXB based models and generate the XML-document at the expected place
extendee modules X, Y, Z
using the annotation of modules A, B, C
using the annotation processors of A, B, C to generate the XML-documents
Goal: it should be easy to create extendee modules such as X, Y, Z
Everything works fine with Java SE 8 where JAXB is still bundled with the JRE.
Update 1
Because the Maven plugins are not ready I'm stuck with v2.3.3 for now.
I changed the following:
I'm providing a classloader when calling JAXBContext.newInstance
I added the following configuration to the maven-bundle-plugin in several modules:
com.sun.xml.bind.v2, *
This solved the java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory issues (it doesn't seem to be the correct solution for this, though), but now the ObjectFactory cannot be located though they were generated.
Update 2
I'm using now a modified jaxb-osgi bundle (see issue) and Apache Aries SPI Fly Dynamic Weaving Bundle (1.3.2) (the reference implementation of the OSGi ServiceLoader Mediator specification) and I added the following requirements to the core module M:
Require-Capability: [...],osgi.extender;filter:="(o
sgi.extender=osgi.serviceloader.processor)",osgi.serviceloader;filter:=
"(osgi.serviceloader=javax.xml.bind.JAXBContextFactory)";cardinality:=m
ultiple,[...]"
The services seem to get detected:
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.xml.bind.v2.JAXBContextFactory of service javax.xml.bind.JAXBContextFactory in bundle com.sun.xml.bind.jaxb-osgi
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.tools.xjc.addon.code_injector.PluginImpl of service com.sun.tools.xjc.Plugin in bundle com.sun.xml.bind.jaxb-osgi
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.tools.xjc.addon.locator.SourceLocationAddOn of service com.sun.tools.xjc.Plugin in bundle com.sun.xml.bind.jaxb-osgi
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.tools.xjc.addon.sync.SynchronizedMethodAddOn of service com.sun.tools.xjc.Plugin in bundle com.sun.xml.bind.jaxb-osgi
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.tools.xjc.addon.at_generated.PluginImpl of service com.sun.tools.xjc.Plugin in bundle com.sun.xml.bind.jaxb-osgi
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.tools.xjc.addon.episode.PluginImpl of service com.sun.tools.xjc.Plugin in bundle com.sun.xml.bind.jaxb-osgi
2021-02-13 12:09:31 INFO org.apache.aries.spifly.BaseActivator log - Registered provider com.sun.tools.xjc.addon.accessors.PluginImpl of service com.sun.tools.xjc.Plugin in bundle com.sun.xml.bind.jaxb-osgi
But I still get:
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory not found by
Why does it try to load the hard-coded default com.sun.xml.bind.v2.ContextFactory instead of com.sun.xml.bind.v2.JAXBContextFactory via ServiceLoader?
Since each OSGI bundle uses its own classloader the JAXB API is not able to use the standard ServiceLoader to locate the JAXB implementation. However since version 2.2.2 the JAXB API can use osgi-resource-locator as a fallback.
Therefore, in order to use JAXB on Java 11, you just need to:
Add a dependency on the javax.xml.bind and org.glassfish.hk2.osgiresourcelocator packages,
Deploy the osgi-resource-locator and jaxb-osgi bundles together with your bundle.
Remark: if you want to use MOXy, you need additional steps, since MOXy does not ship with a META-INF/services/javax.xml.bind.JAXBContext file (cf. this answer).
Want to implement simple mail sender solution based on spring-boot-starter-mail
After adding dependency and set up properties I tried to run app and that error occurred.
I think that's worth noticing that I am not, and not about either to implement Spring Cloud. Just the mail service.
Doesn't understand why spring boot expects some services that are from these package.
Tried various version of dependency, defining some #Beans but don't think that's the issue
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
logs:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-23 00:07:05.752 ERROR 19576 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method mailNotifier in de.codecentric.boot.admin.server.config.AdminServerNotifierAutoConfiguration$MailNotifierConfiguration required a bean of type 'de.codecentric.boot.admin.server.domain.entities.InstanceRepository' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'instanceRepository' in 'AdminServerAutoConfiguration' not loaded because #ConditionalOnBean (types: de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration$Marker; SearchStrategy: all) did not find any beans of type de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration$Marker
Action:
Consider revisiting the entries above or defining a bean of type 'de.codecentric.boot.admin.server.domain.entities.InstanceRepository' in your configuration.
Just want to send email via smtp.gmail.com
Hope that spring-boot-starter-mail 'd be enough for that.
Thanks!
As LHCHIN commented, it was a matter of spring-boot-admin-starter-server and spring-boot-admin-dependencies in <dependencyManagement/>
I would always advice to avoid copy pasting the dependencies with their version. Most of the cases you don't need to specifiy the version and let Spring boot figure out based on mvn which version will be suitable for you.
For the spring boot starter mail, I just needed the following dependencies
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.5.6</version>
</dependency>
The source I used is : https://www.baeldung.com/spring-email and it worked for me with version and without.
Description: I am using MongoDB and it keeps asking for a datasource. I have excluded the following:
exclude=DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class,
JpaRepositoriesAutoConfiguration.class})
error:
Error starting ApplicationContext. To display the conditions report re-run
your application with 'debug' enabled.
2018-10-29 11:03:25.968 ERROR 4676 --- [ restartedMain]
o.s.b.d.LoggingFailureAnalysisReporter :
Description:
***************************
APPLICATION FAILED TO START
***************************
Parameter 1 of method batchConfigurer in org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration$JdbcBatchConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because #ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
- Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required class 'javax.transaction.TransactionManager'
Action:
Consider revisiting the entries above or defining a bean of type 'javax.sql.DataSource' in your configuration.
Spring Boot is intended for building production grade applications. When it is used to build a Spring Batch application, it requires a data source to persist Spring Batch meta-data (See BATCH-2704).
But you can always use either:
an embedded datasource supported by Spring Boot (H2, HSQL or Derby) by just adding it to the classpath. This data source will be picked up automatically by Spring Batch
or provide a custom BatchConfigurer and use the MapJobRepository (See here)
Hope this helps.
I have working Spring WEB MVC application. I need to add Hibernate persistence layer, so I downloaded Spring Pet Clinic application from Github:
http://spring.io/blog/2013/03/21/spring-petclinic-is-on-github
Only changing jars to the set of jars from the Petclinic application (Spring version 4.0.1) results in the following error
12:38:54.039 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'viewResolver'
12:38:54.039 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'viewResolver'
12:38:54.061 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed
java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh(Lorg/springframework/beans/factory/annotation/InjectionMetadata;Ljava/lang/Class;)Z
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:383) ~[spring-orm-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:332) ~[spring-orm-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:844) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
It seems there is a conflict of Spring modules' versions.
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:332) ~[spring-orm-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:844) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
Make sure all your Spring dependencies have the same version.