0

I found following solution but unfortunately I am not able to get it working.

https://stackoverflow.com/a/10998044/2182503

I can successfully compile, but when I test the application, my Spring Beans are always null.

Environment:

  • Tomcat 7
  • JDK 1.7 / JRE7
  • Compiler Version 1.7
  • Spring 3.2.4
  • AspectJ 1.7.3
  • Spring Aspects 4.0.0

POM

....

<!-- AspectJ -->
<dependency>
     <groupId>org.aspectj</groupId>
     <artifactId>aspectjrt</artifactId>
     <version>${aspectj.version}</version>
 </dependency>

 <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-aspects</artifactId>
     <version>${spring.aspects.version}</version>
 </dependency>

....

    <build>
    <pluginManagement>
        <plugins>
            <!-- Maven complier plugin that forces maven to use specified version 
                of JDK/JRE while compilation -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${compiler.version}</source>
                    <target>${compiler.version}</target>
                </configuration>
            </plugin>

            <!-- AspectJ Plugin - For dependency injection with new() -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.5</version>
                <configuration>
                    <complianceLevel>1.7</complianceLevel>
                    <encoding>UTF-8</encoding>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                    <!-- Xlint set to warning alleviate some issues, such as SPR-6819. 
                        Please consider it as optional. https://jira.springsource.org/browse/SPR-6819 -->
                    <Xlint>warning</Xlint>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Less CSS Plugin -->
            <plugin>
                ...
            </plugin>
        </plugins>
    </pluginManagement>
</build>

WebAppConfig:

@Configuration
@EnableWebMvc
@EnableScheduling
@EnableSpringConfigured
@PropertySource("classpath:webapplication.properties")
@ComponentScan("com.root.package")
public class WebAppConfig extends WebMvcConfigurerAdapter {
 ...
}

Month:

public class Month {
     private void fillDaysOfMonth() {  
         ...         
         for (int i = 1; i <= date.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
             Day day = new Day();
             ...
         }
     }    
}

Day:

@Configurable
public class Day {

    @Autowired private AbsenceService absenceService;
    @Autowired private HolidayMasterdataService holidayMasterdataService;
}
Community
  • 1
  • 1
Tunguska
  • 1,205
  • 3
  • 18
  • 37
  • Are your setters and getters of class Day in place – Pratik Shelar Jan 21 '14 at 07:55
  • No they were not. But I added the setters/getters and Beans still get not injected. Is this a special behaviour of @Configurable, because if I autowire the same beans in classes - initialized by Spring - I dont need setters/getters. – Tunguska Jan 21 '14 at 08:04
  • Another question: Do I still need the maven-compiler-plugin? – Tunguska Jan 21 '14 at 08:05
  • Do you have many manually created beans or just a few in your application? – Jakub Kubrynski Jan 21 '14 at 08:22
  • The service beans are custom classes, initialized over '@Service' and '@ComponentScan' annotation by Spring MVC. Each Service and DAO is initialized like this, and they are many. (For each table in database) – Tunguska Jan 21 '14 at 08:45
  • If I try to complie without the maven-compiler-plugin, it fails with: "Dynamic Web Module 3.0 requires Java 1.6 or newer" and "Java compiler level does not match the version of the installed Java project facet." If I change the the compiler version in Project>Properties>Java Compiler, it gets reset after recomplation with aspectj-maven-plugin. – Tunguska Jan 21 '14 at 09:36
  • For autowiring to work you need to have proper setters and getters for the dependency which you plan to inject. – Pratik Shelar Jan 21 '14 at 07:56

0 Answers0