मैं एक पुस्तक Introducing Spring Framework पढ़ रहा हूं और मैं पहले उदाहरण पर अटक गया हूं। मैंने पहले कभी ग्रैडल का उपयोग नहीं किया है। किसी भी तरह संकलक मेरे कोड में इस्तेमाल एनोटेशन को समझ में नहीं आता है। भले ही मैंने वसंत निर्भरता gradle.build
फ़ाइल में उपयोग की है।क्यों इस उदाहरण में ग्रैडल संकलन विफल रहता है?
पूर्णता के लिए मैं इस उदाहरण से सभी 4 फाइलें पोस्ट करूंगा।
build.gradle:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = System.getProperty("mainClass")
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework:spring-context:4.0.5.RELEASE'
}
MessageService.java:
package com.apress.isf.spring;
public interface MessageService {
public String getMessage();
}
HelloWorldMessage.java:
package com.apress.isf.spring;
public class HelloWorldMessage implements MessageService {
public String getMessage(){
return "Hello World";
}
}
Application.java:
package com.apress.isf.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@Configuration
@ComponentScan
public class Application {
@Bean
MessageService helloWorldMessageService() {
return new HelloWorldMessage();
}
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
MessageService service = context.getBean(MessageService.class);
System.out.println(service.getMessage());
}
}
012 उबंटू का उपयोग
gradle run -DmainClass=com.apress.isf.spring.Application
:
मैं के साथ उदाहरण चलाते हैं।
परिणाम है:
~/src/main/java/com/apress/isf/spring/Application.java:7: error: cannot find symbol
@Configuration
^
symbol: class Configuration
~/src/main/java/com/apress/isf/spring/Application.java:8: error: cannot find symbol
@ComponentScan
^
symbol: class ComponentScan
2 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.025 secs
किसी को भी मुझे इस उदाहरण चल के साथ मदद कर सकते हैं? सादर।
वाह। धन्यवाद। किसी तरह मैंने उस बारे में नहीं सोचा था। इस पुस्तक के लिए अभी तक कोई इरेटा नहीं है। धन्यवाद! :) –