Issue 1:
Kai Hackemesser opened SPR-8583 and commented

I have the web application context and the servlet context converted from xml to java config. The web.xml is updated according to the online documentation example. I use @Autowire annotation in the servlet config to get the beans required for the form controllers. I have autowired the web application context config class, too, as I want to retrieve some fields from there that I have @Value annotated, by calling some type converting methods. The autowiring seems to fail as I get Nullpointer exceptions on lines where the webapp config class method is called. I was debugging the server: the web application context has been built using the config class and the fields I want to call methods on are filled properly. The @Autowired config field is null when the @Bean annotated method wants to use it.

Here some short example lines from our project:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
...
<servlet>
...
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.ourcompany.ServletConfig</param-value>
</init-param>
...
</servlet>
...
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.ourcompany.ApplicationConfig
</param-value>
</context-param>
...
</web-app>

ServletConfig.java:

...
@Configuration
@ImportResource("classpath:/META-INF/iem/servletPropertyConfigurer.xml")
public class ServletConfig
{
...
@Autowired
private ApplicationConfig applicationConfig;
...
@Bean
public DbStatsController dbStatsController()
{
DbStatsController controller = new DbStatsController();
controller.setManageUrl(applicationConfig.getDatabaseManageUrl());
...
return controller;
}
...

ApplicationConfig.java:

@Configuration("applicationConfig")
@ImportResource({
"classpath:/META-INF/..." })
public class ApplicationConfig
{
...
@Value("$[database.manage.url]")
private String databaseManageUrl;

...
public String getDatabaseManageUrl()
{
return databaseManageUrl;
}

Following the documentation a Config class can be autowired like any other bean, but it doesn't work here. and I don't get a BeanNotFound or similar exception, it just fails with a NullpointerException when trying to access the autowired field.

Issue Links:

#13226 unresolvable circular reference when bean defined in xml config refers to bean defined in outer java config ("duplicates")

Issue 2:
Kai Hackemesser opened SPR-8583 and commented

I have the web application context and the servlet context converted from xml to java config. The web.xml is updated according to the online documentation example. I use @Autowire annotation in the servlet config to get the beans required for the form controllers. I have autowired the web application context config class, too, as I want to retrieve some fields from there that I have @Value annotated, by calling some type converting methods. The autowiring seems to fail as I get Nullpointer exceptions on lines where the webapp config class method is called. I was debugging the server: the web application context has been built using the config class and the fields I want to call methods on are filled properly. The @Autowired config field is null when the @Bean annotated method wants to use it.

Here some short example lines from our project:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
...
<servlet>
...
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.ourcompany.ServletConfig</param-value>
</init-param>
...
</servlet>
...
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.ourcompany.ApplicationConfig
</param-value>
</context-param>
...
</web-app>

ServletConfig.java:

...
@Configuration
@ImportResource("classpath:/META-INF/iem/servletPropertyConfigurer.xml")
public class ServletConfig
{
...
@Autowired
private ApplicationConfig applicationConfig;
...
@Bean
public DbStatsController dbStatsController()
{
DbStatsController controller = new DbStatsController();
controller.setManageUrl(applicationConfig.getDatabaseManageUrl());
...
return controller;
}
...

ApplicationConfig.java:

@Configuration("applicationConfig")
@ImportResource({
"classpath:/META-INF/..." })
public class ApplicationConfig
{
...
@Value("$[database.manage.url]")
private String databaseManageUrl;

...
public String getDatabaseManageUrl()
{
return databaseManageUrl;
}

Following the documentation a Config class can be autowired like any other bean, but it doesn't work here. and I don't get a BeanNotFound or similar exception, it just fails with a NullpointerException when trying to access the autowired field.

Issue Links:

#13226 unresolvable circular reference when bean defined in xml config refers to bean defined in outer java config ("duplicates")