I am trying to implement a FlyWay java callback. However, flyway doesn't seem to find my class.
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1
/snip.../
Caused by: java.lang.ClassNotFoundException: ch.x.dp.test1
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
It seems that Flyway cannot find the class.
Here my java class:
package ch.x.dp;
import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.callback.Context;
import org.flywaydb.core.api.callback.Event;
public class test1 implements Callback {
public test1() {
System.out.println("sldhksjhdkghd");
}
public boolean supports(Event event, Context context) {
return false;
}
public boolean canHandleInTransaction(Event event, Context context) {
return false;
}
public void handle(Event event, Context context) {
}
}
My pom contains the following:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.0.0-beta2</version>
</dependency>
and
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<configuration>
<locations>classpath:ch.x.dp,filesystem:src/main/resources/db/migration</locations>
<callbacks>
<callback>ch.x.dp.test1</callback>
</callbacks>
<snip/>
</plugin>
I have verified that my mvn package calls create a jar in /target that contains my test1 class.
What else could be missing? How can I tell that FlyWay is actually using that jar?
Related
Background
I have an application with spring data neo4j, and I switched from 4.1.3 to 5.0.0.
I believe that I have made all the necessary changes to convert my code over but I still get errors.
My current version of spring boot is
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
Problem
When I run: mvn spring-boot:run in the command line,
I get an error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field actionRepository in myproject.service.ActionServiceImpl required a bean of type 'myproject.repository.ActionRepository' that could not be found.
Action:
Consider defining a bean of type 'myproject.repository.ActionRepository' in your configuration
My myproject.Application.java is currently
#SpringBootApplication
#EnableTransactionManagement
#EnableSwagger2
#EntityScan(basePackages = "myproject.domain")
public class Application {
public static void main(String[] args) {
new SpringApplication(Application.class).run(args);
}
#Bean
public Docket Api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.apiInfo(apiInfo());
}
private springfox.documentation.service.ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Service API")
}
}
And this does not find any of my controllers like myproject.controller.ActionController.java which contains
...
#RestController
#Api(value = "Action", description = "Actions Management API")
#RequestMapping(value = "/api/action")
public class ActionController extends Controller<Action> {
...
Attempt #1
If I add the annotation #ComponentScan({"myproject.request"}) to my Application class, the error goes away, but spring boot cannot load any controllers and as such my Swagger shows no APIs and no controllers are run. This is not the solution. #SpringBootApplication should take care of all this.
Question
How do I reconfig spring boot to start working like it did in version 4.1.3 of spring data neo4j?
UPDATE 1 ATTEMPT #2
I tried adding this annotation to my class Application
#EnableNeo4jRepositories("myproject.repository")
And the error changed to something less clean:
...
2017-10-05 13:19:46.992 ERROR 561 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
at org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension.postProcess(Neo4jRepositoryConfigurationExtension.java:110) ~[spring-data-neo4j-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:130) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) ~[spring-data-commons-1.12.0.RELEASE.jar:na]
...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -> [Help 1]
[ERROR]
...
UPDATE 2
In an attempt to use the #EnableNeo4jRepositories("myproject.repository") and bypass the error in Update 1, I tried:
mvn clean install spring-boot:repackage
And it gave a Build Success, but the same error persists:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.1.RELEASE:run (default-cli) on project myproject: An exception occurred while running. null: InvocationTargetException: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; -
UPDATE 3
I have the new annotation and changed my pom from:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.0.RELEASE</version>
</dependency>
to
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
and now mvn spring-boot:run
gives the error:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'getSessionFactory' that could not be found.
Action:
Consider defining a bean named 'getSessionFactory' in your configuration.
Try adding this annotation on your configuration class :
#EnableNeo4jRepositories("myproject.repository")
Update :
I just saw you're on Spring boot 1.4. SDN 5 is only compatible with Spring Boot 2.0.
Details are in the compatibility table.
so here i am - running a spring application with spring roo behind.
i use to cut my controllers into aspects, so my main controller will look like this:
#Controller
#RequestMapping("/apples")
#SessionAttributes(types = {Apple.class})
public class AppleController {
}
and other aspects extend its functionality like:
privileged aspect AppleController_Basics {
#RequestMapping(value = "/allApples", produces = "text/html", method=RequestMethod.GET)
public String AppleController.allApples(Model model) {
...
return "apples/list";
}
}
Now when i try to use Java 8 stream API within the aspect like:
apples.stream().filter(a -> a.isSweet()).collect(Collectors.toList());
i am facing the following exception:
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: com.apple.web.AppleController.lambda$0(Lcom/apple/model/Apple;)Z
when i use stream API for another entity than Apple itself, i get a slight different exception:
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.BootstrapMethodError: java.lang.IllegalAccessError: tried to access method com.apple.web.AppleController.lambda$0(Lcom/apple/security/AppleEater;)Z from class com.apple.web.aspects.AppleController_Basics
when using forEach i get OutOfMemoryError::
apples.forEach(System.out::println);
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space
when i use those expressions in the main class, everything works fine.
the plugin looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.9</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.10</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.10</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<complianceLevel>1.8</complianceLevel>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.8</source>
<target>1.8</target>
<showWeaveInfo>true</showWeaveInfo>
<weaveWithAspectsInMainSourceFolder>false</weaveWithAspectsInMainSourceFolder>
</configuration>
</plugin>
i tried diffrent things to change my aspectj plugin configuration in order to make it work - without success. i appreciate any hint or help as i am really confused right now, pls dont hate <3
javap -c -p AppleController.class
public java.lang.String allApples(org.springframework.ui.Model);
Code:
0: aload_0
1: aload_1
2: invokestatic #528 // Method com/apple/web/aspects/AppleController_Basics.ajc$interMethod$com_apple_web_aspects_AppleController_Basics$com_apple_web_AppleController$allApples:(Lcom/apple/web/AppleController;Lorg/springframework/ui/Model;)Ljava/lang/String;
5: areturn
This is obviously an AspectJ compiler bug or shortcoming. I have created a bug ticket for it.
Here is the (non-Spring) test case I have extracted from your code:
package de.scrum_master.app;
public class Apple {
private String type;
private boolean sweet;
public Apple(String type, boolean sweet) {
this.type = type;
this.sweet = sweet;
}
public String getType() {
return type;
}
public boolean isSweet() {
return sweet;
}
}
package de.scrum_master.app;
import java.util.Arrays;
import java.util.List;
public class AppleController {
private static final List<Apple> APPLES =
Arrays.asList(new Apple("Granny Smith", false), new Apple("Golden Delicious", true));
public static void main(String[] args) {
AppleController appleController = new AppleController();
System.out.println("Named: " + appleController.namedApples(APPLES, "Smith"));
System.out.println("Sweet: " + appleController.sweetApples(APPLES));
System.out.println("Sour: " + appleController.sourApples(APPLES));
}
}
package de.scrum_master.aspect;
import java.util.List;
import java.util.stream.Collectors;
import java.util.function.Predicate;
import de.scrum_master.app.Apple;
import de.scrum_master.app.AppleController;
public privileged aspect AppleControllerITDAspect {
public List<Apple> AppleController.namedApples(List<Apple> apples, String subString) {
// Anonymous subclass works
return apples.stream().filter(new Predicate<Apple>() {
#Override
public boolean test(Apple a) {
return a.getType().contains(subString);
}
}).collect(Collectors.toList());
}
public List<Apple> AppleController.sweetApples(List<Apple> apples) {
// Method reference works
return apples.stream().filter(Apple::isSweet).collect(Collectors.toList());
}
public List<Apple> AppleController.sourApples(List<Apple> apples) {
// Lambda causes IllegalAccessError
return apples.stream().filter(a -> !a.isSweet()).collect(Collectors.toList());
}
}
The console log looks like this:
Named: [de.scrum_master.app.Apple#6f496d9f]
Sweet: [de.scrum_master.app.Apple#4e50df2e]
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.IllegalAccessError: tried to access method de.scrum_master.app.AppleController.lambda$0(Lde/scrum_master/app/Apple;)Z from class de.scrum_master.aspect.AppleControllerITDAspect
at de.scrum_master.aspect.AppleControllerITDAspect.ajc$interMethod$de_scrum_master_aspect_AppleControllerITDAspect$de_scrum_master_app_AppleController$sourApples(AppleControllerITDAspect.aj:28)
at de.scrum_master.app.AppleController.sourApples(AppleController.java:1)
at de.scrum_master.aspect.AppleControllerITDAspect.ajc$interMethodDispatch1$de_scrum_master_aspect_AppleControllerITDAspect$de_scrum_master_app_AppleController$sourApples(AppleControllerITDAspect.aj)
at de.scrum_master.app.AppleController.main(AppleController.java:14)
Caused by: java.lang.IllegalAccessError: tried to access method de.scrum_master.app.AppleController.lambda$0(Lde/scrum_master/app/Apple;)Z from class de.scrum_master.aspect.AppleControllerITDAspect
at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.lang.invoke.MemberName$Factory.resolve(Unknown Source)
at java.lang.invoke.MemberName$Factory.resolveOrFail(Unknown Source)
at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(Unknown Source)
at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(Unknown Source)
at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(Unknown Source)
... 4 more
In the aspect above you can also see a temporary workaround: use a method reference or a classical anonymous subclass instead of a lambda.
Background info: The AspectJ compiler AJC is a regularly updated fork of the Eclipse Java compiler ECJ (AspectJ is also an official Eclipse project, BTW). So maybe the bug is in ECJ, but probably rather in AJC.
Now that method:
lambda$0(Lcom/apple/model/Apple;)Z
is actually the de-sugar of your lambda a -> a.isSweet(), which will look like this:
private static boolean lambda$0(Apple s){
return s.isSweet();
}
This method is generated by the compiler. Unless you are using some weird compiler, this would have to be a bug in aspectj.
You can check that the method is there in AppleController by invoking the command to decompile your .class file:
javap -c -p AppleController.class
where the output should be something like this:
private static boolean lambda$0(com.model.apple.Apple);
Code:
0: aload_0
1: invokevirtual #9 // Method isSweet:()Z
4: ireturn
If this method is indeed there (the javac did his job correctly), you theoretically can not get a java.lang.NoSuchMethodError, which means that
aspectj is doing something very funny in the version that you are using.
I highly doubt this last paragraph, but just in case...
On the other hand if you de-compile (javap command) and you do not see the lambda$0 method, but one called lambda$main$0 for example, it means you are compiling with jdk-9 or some non-obvious Eclipse compiler.
Im unable to run the generated jar file with my spring-boot with jersey project.
exception that i encounter is:
Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 1
Project runs properly when it's done via IDE (running the Main class) or when using spring-boot:run
Here are the details of the current setup:
Packaging:
jar
dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
my jersey configuration (ResourceConfig) is set to scan packages
#Component
public class JerseyConfiguration extends ResourceConfig {
public JerseyConfiguration() {
packages(true, "com.my.base.jaxrs.packages");
}
}
spring-boot-maven-plugin configured as:
org.springframework.boot
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
I also did not use the spring-boot-starter-parent but added the spring-boot-dependencies as indicated in the docs.
This is more of a workaround than an actual valid solution to use
packages(true, "my.package");
in reference to Anton's answer, i settled with this solution with the limitation that it requires resources with class level #Path or #Provider annotation:
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Path.class));
provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
provider.findCandidateComponents("my.package.here").forEach(beanDefinition -> {
try {
LOGGER.info("registering {} to jersey config", beanDefinition.getBeanClassName());
register(Class.forName(beanDefinition.getBeanClassName()));
} catch (ClassNotFoundException e) {
LOGGER.warn("Failed to register: {}", beanDefinition.getBeanClassName());
}
});
I had this problem, I did not want to complicate things too much so I just registered all my jersey controllers individually.
#Configuration
public class JerseyConfig extends ResourceConfig {
JerseyConfig() {
// my old version that does not play well with spring boot fat jar
/*
packages(
"com.mycompany.api.resources"
);
*/
register(com.mycompany.api.resources.FooController.class);
register(com.mycompany.api.resources.BarController.class);
}
NOTE: I would not recommend this for large projects with many files, it will very quickly become long and unreadable and tedious to maintain.
That said, it is a working solution and you will be able to run your jar with the usual java -jar my-project.jar command.
Alternatively you could do,
#Configuration
public class JerseyConfig extends ResourceConfig {
JerseyConfig() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setResourcePackage("com.mycompany.api.resources");
}
}
This is a sample code that i took from the aether sample codes to fetch an artifact.
public class Main2 {
public static void main(String[] args) throws Exception {
DefaultServiceLocator locator = new DefaultServiceLocator();
locator.addService(RepositoryConnectorFactory.class, FileRepositoryConnectorFactory.class);
locator.addService(RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class);
locator.addService(VersionResolver.class, DefaultVersionResolver.class);
locator.addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class);
locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
locator.setServices(WagonProvider.class, new WagonProvider() {
public Wagon lookup(String roleHint) throws Exception {
if ("http".equals(roleHint)) {
return new LightweightHttpWagon();
}
return null;
}
public void release(Wagon wagon) {
}
});
RepositorySystem system = locator.getService(RepositorySystem.class);
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
LocalRepository localRepo = new LocalRepository("target/local-repo");
session.setLocalRepositoryManager(system.newLocalRepositoryManager(localRepo));
Artifact artifact = new DefaultArtifact("com.hazelcast:hazelcast:LATEST");
RemoteRepository repo = new RemoteRepository("central", "default", "http://repo1.maven.org/maven2/");
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.addRepository(repo);
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
artifact = artifactResult.getArtifact();
System.out.println(artifact + " resolved to " + artifact.getFile());
}
}
This code is to fetch the artifact from maven central but it is throwing this error:
Exception in thread "main" org.sonatype.aether.resolution.ArtifactResolutionException: Could not transfer artifact com.hazelcast:hazelcast:jar:3.4.1 from/to central (http://repo1.maven.org/maven2/): NullPointerException
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:541)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:220)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:197)
at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:323)
at maven.test.poc1.Main2.main(Main2.java:69)
Caused by: org.sonatype.aether.transfer.ArtifactTransferException: Could not transfer artifact com.hazelcast:hazelcast:jar:3.4.1 from/to central (http://repo1.maven.org/maven2/): NullPointerException
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:951)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:941)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:669)
at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.apache.maven.wagon.providers.http.LightweightHttpWagon.openConnectionInternal(LightweightHttpWagon.java:266)
at org.apache.maven.wagon.AbstractWagon.openConnection(AbstractWagon.java:105)
at org.apache.maven.wagon.AbstractWagon.connect(AbstractWagon.java:207)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector.connectWagon(WagonRepositoryConnector.java:345)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector.pollWagon(WagonRepositoryConnector.java:385)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:571)
... 4 more
Please someone suggest what change has to be there.
This is a sample code that i took from aether sample codes.
This is a general problem with the latest version (1.13.1) of the org.apache.maven.wagon:wagon-http-lightweight. When used with the latest version of the other aether and maven dependencies it is throwing error.
So don't use the latest version, use the older version. These are the dependencies that i used which worked for me along with the code mentioned in my question.
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-util</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>1.0</version>
</dependency>
and the code to download the artifact from the repository is as mentioned below
public class Main2 {
public static void main(String[] args) throws Exception {
DefaultServiceLocator locator = new DefaultServiceLocator();
locator.addService(RepositoryConnectorFactory.class, FileRepositoryConnectorFactory.class);
locator.addService(RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class);
locator.addService(VersionResolver.class, DefaultVersionResolver.class);
locator.addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class);
locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
locator.setServices(WagonProvider.class, new WagonProvider() {
public Wagon lookup(String roleHint) throws Exception {
if ("http".equals(roleHint)) {
return new LightweightHttpWagon();
}
return null;
}
public void release(Wagon wagon) {
}
});
RepositorySystem system = locator.getService(RepositorySystem.class);
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
LocalRepository localRepo = new LocalRepository("target/local-repo");
session.setLocalRepositoryManager(system.newLocalRepositoryManager(localRepo));
Artifact artifact = new DefaultArtifact("com.hazelcast:hazelcast:LATEST");
RemoteRepository repo = new RemoteRepository("central", "default", "http://repo1.maven.org/maven2/");
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.addRepository(repo);
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
artifact = artifactResult.getArtifact();
System.out.println(artifact + " resolved to " + artifact.getFile());
}
}
I am having an strange behavior, using spring 4.1.1 I get this error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project newvalia-view: Compilation failure
[ERROR] /C:/Users/edu/IdeaProjects/newvalia/newvalia- view/src/main/java/com/newvalia/web/init/WebInitContext.java:[19,12] cannot access org.springframework.context.annotation.AnnotationConfigRegistry
[ERROR] class file for org.springframework.context.annotation.AnnotationConfigRegistry not found
while if I downgrade to spring 4.0.7 it compiles correctly.
I am using simple spring webmwc configuration :
#Configuration
#ComponentScan(value = "com.newvalia.web")
#EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
}
public class WebInitContext implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext container) {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebMvcConfig.class);
ctx.setServletContext(container);
Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
}
is this a new expected behavior?
import org.springframework.context jar correctly in your pom file , and thats it .
Hope that Helps .
Add spring context dependency :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>