这是通常的代码:
@Autowire
private Service service;
Run Code Online (Sandbox Code Playgroud)
但是使用Java 7,这也可以(并且更短):
private @Autowire Service service;
Run Code Online (Sandbox Code Playgroud)
这在Java 8中是否合法(具有相同的语义)?这是不好的编码练习吗?
这是我的课:
@Repository
@RequiredArgsConstructor
@Slf4j
public class ServeiTerritorialCatalegsClientRepositoryImpl implements ServeiTerritorialCatalegsClientRepository {
@Qualifier("catalegsMarshaller") private final Marshaller marshaller;
//...
}
Run Code Online (Sandbox Code Playgroud)
我的 bean 定义是:
@Bean
public Marshaller oidMarshaller() throws JAXBException {
//...
}
@Bean
public Marshaller catalegsMarshaller() throws JAXBException {
//...
}
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 3 of constructor in cat.catsalut.hes.mpi.hazelcast.loader.repository.ServeiTerritorialCatalegsClientRepositoryImpl required a single bean, but 2 were found:
- oidMarshaller: defined by method 'oidMarshaller' in class path resource [cat/catsalut/hes/mpi/hazelcast/loader/configuration/ServeiTerritorialConfiguration.class]
- catalegsMarshaller: defined by method 'catalegsMarshaller' in class path …
Run Code Online (Sandbox Code Playgroud)