I am following this tutorial about how to use Spring and based on the provided example, I get the following exception:
Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: com.tutorialspoint.HelloWorldConfig
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:378)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
at com.tutorialspoint.MainApp.main(MainApp.java:9)
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:128)
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:100)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:368)
... 7 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 12 more
Caused by: java.lang.SecurityException: class "com.tutorialspoint.HelloWorldConfig$$EnhancerBySpringCGLIB$$b5aece24"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:952)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:666)
at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
... 18 more
I have researched my problem and have found this; someone also has had the same problem as me, and it has something to do with ensuring that ASM is compatible with CGLIB. However I have tried this solution and it has not worked, I even went as far as using the exact same versions as the one provided (GBLIB 2.2.2 and ASM 3.3.1).
What do I need to do in order to correct this?
For simplicity, here are the files which I am using that were extracted from the provided tutorial.
HelloWorldConfig.java
package com.tutorialspoint;
import org.springframework.context.annotation.*;
#Configuration
public class HelloWorldConfig {
#Bean
public HelloWorld helloWorld() {
return new HelloWorld();
}
}
HelloWorld.java
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void setMessage(String message) {
this.message = message;
}
public void getMessage() {
System.out.println("Your Message : " + message);
}
}
MainApp.java
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
public class MainApp {
public static void main(String[] args) {
#SuppressWarnings("resource")
ApplicationContext ctx = new AnnotationConfigApplicationContext(
HelloWorldConfig.class);
HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
helloWorld.setMessage("Hello World!");
helloWorld.getMessage();
}
}
Also by saying 'However I have tried this solution and it has not worked' I mean that the exact same error is returned.
I had the same problem and realized the JRE version I have in the POM.xml or the default one associated with the project was not set in the class path. So updated the same under Preferences -> Installed JREs and ran the application it worked.
Gone through this problem yesterday and
Here is the solution.
Open Eclipse
Open window in menu bar -> preferences -> java ->installed jre
add new jre which is installed in system(c:program_files->java->jre->bin) add it.
Select the new added jre and BOOOM 🔥🔥
This problem occurred due to spring dependency problem, I too used below dependency facing same issue, the configuration classes didn't loaded
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
Try below one: for me it is working
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
So, i would say the "other" you mentioned, has an different problem.
Even when the "Last-Shown-Exception" is the same as yours.
But as you can see in your stacktrace, the "source" is a SecurityException.
The *Cannot load configuration class*-Error is a aftereffect
I assume there is something wrong with the "code signation" in your project
or, due to ByteCode-Manipulation, the signation is broken.
PS:
Sometimes this also can happen, when you reference "SignedLibs" and "UnsignedLibs" in your project.
in this case remove the signation from the signed libs.
All jars required for this project to run:
1) org.springframework.core-3.0.1.RELEASE-A.jar
2) spring-context-3.0.4.RELEASE.jar
3) org.springframework.beans-3.0.1.RELEASE-A.jar
4) commons-logging-1.1.1.jar
5) asm-3.3.1.jar
6) cglib-2.2.2.jar
To get these jars,either add the downloaded jars to your project directly, or provide the following dependencies in the pom.xml to get them automatically downloaded for you.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
Add this to your maven settings.xml file if not already present:
<profiles>
<profile>
<id>SPRINGLEARN</id>
<activation>
<jdk>1.8</jdk>
</activation>
<repositories>
<repository>
<id>thirdPartyRepo</id>
<name>Third party repository</name>
<url>https://repo.spring.io/libs-release/</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>thirdPartyPluginRepo</id>
<name>Third party plugin repository</name>
<url>https://repo.spring.io/libs-release/</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
After this, just run your project.
-Right click on your project -> Run as -> Maven clean
-Right click on your project -> Run as -> Maven install
-Right click on your project -> Run as -> Java application
I too faced this issue.
Use the latest version of spring. works in versions of 5.
Check out the POM.xml for suitable dependencies
enter image description here
and also JRE as well... it will work with java 1.7
Related
I'm trying to send email using SpringMVC. I've made a bean JavaMailSender and get an error.
#Bean
public JavaMailSender javaMailSender(){
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setUsername("test");
javaMailSender.setPassword("test");
javaMailSender.setPort(56);
javaMailSender.setHost("smtp.test.ru");
return javaMailSender;
}
Error:
04-Dec-2016 20:05:50.699 SEVERE [RMI TCP Connection(31)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
java.lang.NoClassDefFoundError: org/springframework/mail/javamail/JavaMailSender
My context with this bean:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
#Configuration
#PropertySource("classpath:util.properties")
#PropertySource(value = {"classpath:auth.properties"})
public class MailContext {
#Bean
public JavaMailSender javaMailSender(){
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setUsername("test");
javaMailSender.setPassword("test");
javaMailSender.setPort(556);
javaMailSender.setHost("test.ru");
javaMailSender.setProtocol("smtp");
Properties properties = new Properties();
properties.setProperty("mail.debug", "true");
javaMailSender.setJavaMailProperties(properties);
return javaMailSender;
}
}
My pom :
...
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
...
What did I do wrong?
It appears that you need, but do not have spring-context-support-4.3.4.RELEASE.jar on your classpath.
To add this to your application's classpath in IntelliJ, edit your project's Project Structure, and add a Library under Libraries referencing the Spring jar file. Add or edit your Module and add the library to the Module. Add or edit Artifacts and make sure the library or module is one of the Available Elements for the Artifact.
Under the Run menu, click Edit Configurations for your Tomcat configuration, on the Deployment tab, add the artifact (or library) to the Deploy at server startup list.
This information at JetBrains provides more information on configuring your Intellij setup to get desired jars on your classpath.
It is also possible that you need to make a simple configuration change to your dependency in your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.4.RELEASE</version>
<scope>runtime</scope>
</dependency>
(NOTE the addition of the <scope> element. More information on Maven scopes available here.)
(These instructions may vary depending on the version of Intellij that you are using.)
In summary, you need to get the Spring jar on your application's classpath at runtime.
I am trying to convert JSON to JAVA object with the use of GSON in MAVEN, I am following a youtube video for guidance - https://www.youtube.com/watch?v=Vqgghm9pWe0 , however theres an error which occurs when in the Main Class the error is - package com.squareup.okhttp3 doesn't exist. The code is below:
Java
package com.codebeasty.json;
import com.squareup.okhttp3.OkHttpClient;
public class Main {
private static OkHttpClient client = new OkHttpClient();
public static void main (String [] args)
{
}
}
I even put in the dependency in pom.xml:
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
I dont understand why it doesn't recognize the com.squareup. Is there something extra I may need to download? I have downloaded the JAR from this website - http://square.github.io/okhttp/ and also tried building the project with dependencies. Please help :(
Maven repo has latest version 3.4.1. Trying changing version in pom or install downloaded in your local using
mvn install:install-file -Dfile=path/to/okhttp-3.4.2.jar -DgroupId=com.squareup.okhttp3 -DartifactId=okhttp -Dversion=3.4.2 -Dpackaging=jar
I want to create a full WebArchive for running Arquillian Tests using the new ShrinkWrap Feature MavenImporter (https://github.com/shrinkwrap/resolver).
The Scenario:
Arquillian should be integrated/extended with SoapUi to test a Spring application. There are n Endpoints exposed by the Spring application and implemented with cxf.
The test method looks like this:
/*
* Source folder for SoapUi project files
*/
#Value("${soapui.workspace}")
private String soapUiWorkspace;
/*
* Output directory for test reports
*/
#Value("${soapUi.reports.dir}")
private String reportsOutpuDirectory;
/*
* Comma separated list of SoapUi projects to be tested
*/
#Value("${soapUi.projects}")
private String[] projects;
/*
* URL resource provided by Arquillian runtime
*/
#ArquillianResource
private URL serverUrl;
#Test
public void testServiceEndpoints() throws Exception {
final SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
for (String project : projects) {
runner.setProjectFile(String.format("%s%s%s", soapUiWorkspace, "/", project));
runner.setHost(String.format("%s:%s", serverUrl.getHost(), serverUrl.getPort()));
runner.setOutputFolder(reportsOutpuDirectory);
LOG.info("SoapUi-Call for " + runner.getHost());
runner.setJUnitReport(true);
runner.setPrintReport(true);
runner.run();
}
}
My #Deployment-Method looks like this:
#Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(MavenImporter.class).loadPomFromFile("pom.xml").importBuildOutput().as(WebArchive.class);
}
I'm getting right now this Exception:
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.Archive com.bosch.mome.ws.facade.common.soapui.MarketTransparencyServiceEndpointsSoapUiTest.createDeployment()
at org.jboss.shrinkwrap.api.UnknownExtensionTypeException.newInstance(UnknownExtensionTypeException.java:68)
at org.jboss.shrinkwrap.api.UnknownExtensionTypeExceptionDelegator.newExceptionInstance(UnknownExtensionTypeExceptionDelegator.java:37)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.findExtensionImpl(ServiceExtensionLoader.java:279)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.loadExtensionMapping(ServiceExtensionLoader.java:246)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.createFromLoadExtension(ServiceExtensionLoader.java:212)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.load(ServiceExtensionLoader.java:108)
at org.jboss.shrinkwrap.impl.base.ArchiveBase.as(ArchiveBase.java:662)
at org.jboss.shrinkwrap.api.ArchiveFactory.create(ArchiveFactory.java:150)
at org.jboss.shrinkwrap.api.ShrinkWrap.create(ShrinkWrap.java:163)
at com.bosch.mome.ws.facade.common.soapui.MarketTransparencyServiceEndpointsSoapUiTest.createDeployment(MarketTransparencyServiceEndpointsSoapUiTest.java:82)
Jan 19, 2015 6:29:46 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-127.0.0.1-8888
I'm not adding the Assets separately because I'm integrating currently the junit SoapUi library and Arquillian for testing Endpoints and need to load the full Application/WebArchive.
I was looking to the ShrinkWrap javadoc but could not find a working solution/fix.
In the javadoc I read the following:
UnknownExtensionTypeException: Indicates that a default name cannot be generated for a given type because no extension mapping has been configured via ExtensionLoader.getExtensionFromExtensionMapping(Class)
But I don't know where I can exactly configure the Extension mapping. There is no tutorial or samples. Or may be I could not find them.
Does anybody have Experience with this new ShrinkWrap Feature?
I know it has been some time but maybe somebody finds it helpfull anyways.
I had the same problem and the cause was that i was to greedy in my pom.xml. I had the following dependencies:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>test</scope>
</dependency>
Turns out the error just disappears if you use the BOM and the depchain somewhat like this:
<dependencyManagement>
<dependencies>
...
<!-- Override dependency resolver with latest version.
This must go *BEFORE* the Arquillian BOM. -->
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.11.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
...
</dependencies>
</dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>test</scope>
<type>pom</type>
</dependency>
...
<!-- your container goes here, too (for me it was arquillian-tomee-embedded) -->
</dependencies>
Also check out the documentation: https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc
The below behavior occurs when i call the getSftpUtil(). I have also ensured that all the appropriate jars are in the maven project's external libraries and are available in the WEB-INF/lib folder of the project
code
net.sf.opensftp.SftpUtil util = SftpUtilFactory.getSftpUtil();
stacktrace
SftpUtilFactory: Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory - Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory: The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory - The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory: Use the default one.
SftpUtilFactory - Use the default one.
Caused by: java.lang.NoSuchMethodError: com.jcraft.jsch.JSch.setLogger(Lcom/jcraft/jsch/Logger;)V
at net.sf.opensftp.impl.SftpUtil.<clinit>(SftpUtil.java:110)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at net.sf.opensftp.SftpUtilFactory.getSftpUtil(SftpUtilFactory.java:184)
Based on jcraft's change log, setLogger is a method added to JSch.java in jsch-0.1.30. So the jar under your WEB-INF/lib should be an older version.
You can run
mvn dependency:tree
to see which of your dependencies is using the older version, and then exclude it with something like this:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</exclusion>
</exclusions>
</dependency>
You probably have another dependency refer to a more recent version of jsch, so your problem should be solved at this point. However, if that's not the case, you can add this to pom.xml:
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
Well, I guess you are missing this dependency or the proper version:
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version> <!--latest version -->
I am new to EHCache and tried to use it as our cache server. I wrote the code trying to get started:
public class CacheMap {
private static CacheManager cacheManager=new CacheManager("ehcache.xml");
private static Cache cache=cacheManager.getCache("firstCache");
}
In classpath, I have included terracotta-toolkit-1.6-5.2.0.jar, terracotta-toolkit-1.6-runtime-5.0.0, slf4j-api-1.6.6, slf4j-jdk14-1.6.6, ehcache-2.7.0 and ehcache-ee-2.7.0
And I have ehcache.xml in my root directory.
However, I have got the following error on first line of my code:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: net.sf.ehcache.CacheException: Could not create ClusteredInstanceFactory due to missing class. Please verify that terracotta-toolkit is in your classpath.
at net.sf.ehcache.terracotta.TerracottaClusteredInstanceHelper.newClusteredInstanceFactory(TerracottaClusteredInstanceHelper.java:187)
at net.sf.ehcache.terracotta.TerracottaClient.createNewClusteredInstanceFactory(TerracottaClient.java:169)
at net.sf.ehcache.terracotta.TerracottaClient.createClusteredInstanceFactory(TerracottaClient.java:126)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:442)
at net.sf.ehcache.CacheManager.init(CacheManager.java:392)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:291)
at CacheMap.<clinit>(CacheMap.java:7)
Any ideas how to get Terracotta working?
I think you have mixed required terracotta jars. If you use maven here are the dependencies for terracotta ver. 3.6.5 (the last version compatible with JDK5):
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core-ee</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-terracotta-ee</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.terracotta</groupId>
<artifactId>terracotta-toolkit-1.5-runtime-ee</artifactId>
<version>4.5.0</version>
</dependency>
Also don't forget to point to terracotta's maven repository to download required jars:
<repository>
<id>terracotta-repository</id>
<url>http://www.terracotta.org/download/reflector/releases</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
If you are not using maven, then you should have on your classpath the following jars:
ehcache-core-ee-2.5.6.jar
ehcache-terracotta-ee-2.5.6.jar
terracotta-toolkit-1.5-runtime-ee-4.5.0.jar