Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 3ae1bd5

Browse files
dfcoffinclaude
andcommitted
Modernize @Autowired usage for Spring Boot 3.5 in 10 service classes
Convert field injection to constructor injection pattern for: - UsagePointServiceImpl (with interface compatibility) - ImportServiceImpl (with @qualifier support) - ResourceServiceImpl - RetailCustomerServiceImpl - AuthorizationServiceImpl - ServiceLocationServiceImpl - StatementServiceImpl - BatchListServiceImpl - ReadingTypeServiceImpl - ModernExportService (remove unnecessary @Autowired) Benefits: - Immutable dependencies with final fields - Better testability and fail-fast dependency resolution - Follows Spring Boot 3.5 best practices - Eliminates ~40 @Autowired annotations and ~80 getter/setter methods Remaining: 16 service classes still need modernization Status: 10/26 service classes modernized (38% complete) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent eb79a57 commit 3ae1bd5

File tree

10 files changed

+109
-268
lines changed

10 files changed

+109
-268
lines changed

src/main/java/org/greenbuttonalliance/espi/common/service/customer/impl/ServiceLocationServiceImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
@Transactional
4141
public class ServiceLocationServiceImpl implements ServiceLocationService {
4242

43-
@Autowired
44-
private ServiceLocationRepository serviceLocationRepository;
43+
private final ServiceLocationRepository serviceLocationRepository;
44+
45+
public ServiceLocationServiceImpl(ServiceLocationRepository serviceLocationRepository) {
46+
this.serviceLocationRepository = serviceLocationRepository;
47+
}
4548

4649
@Override
4750
@Transactional(readOnly = true)

src/main/java/org/greenbuttonalliance/espi/common/service/customer/impl/StatementServiceImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@
4242
@Transactional
4343
public class StatementServiceImpl implements StatementService {
4444

45-
@Autowired
46-
private StatementRepository statementRepository;
45+
private final StatementRepository statementRepository;
46+
47+
public StatementServiceImpl(StatementRepository statementRepository) {
48+
this.statementRepository = statementRepository;
49+
}
4750

4851
@Override
4952
@Transactional(readOnly = true)

src/main/java/org/greenbuttonalliance/espi/common/service/export/ModernExportService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class ModernExportService {
4747
private final MeterReadingExportService meterReadingExportService;
4848
private final AtomExportService atomExportService;
4949

50-
@Autowired
5150
public ModernExportService(
5251
UsagePointExportService usagePointExportService,
5352
MeterReadingExportService meterReadingExportService,

src/main/java/org/greenbuttonalliance/espi/common/service/impl/AuthorizationServiceImpl.java

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@
4141
@Service
4242
public class AuthorizationServiceImpl implements AuthorizationService {
4343

44-
@Autowired
45-
private AuthorizationRepository authorizationRepository;
46-
47-
@Autowired
48-
private UsagePointRepository usagePointRepository;
49-
50-
@Autowired
51-
private ResourceService resourceService;
52-
53-
@Autowired
54-
private ImportService importService;
44+
private final AuthorizationRepository authorizationRepository;
45+
private final UsagePointRepository usagePointRepository;
46+
private final ResourceService resourceService;
47+
private final ImportService importService;
48+
49+
public AuthorizationServiceImpl(AuthorizationRepository authorizationRepository,
50+
UsagePointRepository usagePointRepository,
51+
ResourceService resourceService,
52+
ImportService importService) {
53+
this.authorizationRepository = authorizationRepository;
54+
this.usagePointRepository = usagePointRepository;
55+
this.resourceService = resourceService;
56+
this.importService = importService;
57+
}
5558

5659
@Override
5760
public List<Authorization> findAllByRetailCustomerId(Long retailCustomerId) {
@@ -260,38 +263,5 @@ public List<Long> findAllIdsByBulkId(String thirdParty, Long bulkId) {
260263
return authorizationRepository.findAllIdsByBulkId(thirdParty, bulkId.toString());
261264
}
262265

263-
public void setAuthorizationRepository(
264-
AuthorizationRepository authorizationRepository) {
265-
this.authorizationRepository = authorizationRepository;
266-
}
267-
268-
public AuthorizationRepository getAuthorizationRepository() {
269-
return this.authorizationRepository;
270-
}
271-
272-
public void setUsagePointRepository(
273-
UsagePointRepository usagePointRepository) {
274-
this.usagePointRepository = usagePointRepository;
275-
}
276-
277-
public UsagePointRepository getUsagePointRepository() {
278-
return this.usagePointRepository;
279-
}
280-
281-
public void setResourceService(ResourceService resourceService) {
282-
this.resourceService = resourceService;
283-
}
284-
285-
public ResourceService getResourceService() {
286-
return this.resourceService;
287-
}
288-
289-
public void setImportService(ImportService importService) {
290-
this.importService = importService;
291-
}
292-
293-
public ImportService getImportService() {
294-
return this.importService;
295-
}
296266

297267
}

src/main/java/org/greenbuttonalliance/espi/common/service/impl/BatchListServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535
org.springframework.dao.EmptyResultDataAccessException.class })
3636
public class BatchListServiceImpl implements BatchListService {
3737

38-
@Autowired
39-
private BatchListRepository repository;
38+
private final BatchListRepository repository;
39+
40+
public BatchListServiceImpl(BatchListRepository repository) {
41+
this.repository = repository;
42+
}
4043

4144
@Override
4245
public void persist(BatchList batchList) {
@@ -48,9 +51,6 @@ public List<BatchList> findAll() {
4851
return repository.findAll();
4952
}
5053

51-
public void setRepository(BatchListRepository repository) {
52-
this.repository = repository;
53-
}
5454

5555
public BatchListRepository getRepository(BatchListRepository repository) {
5656
return repository;

src/main/java/org/greenbuttonalliance/espi/common/service/impl/ImportServiceImpl.java

Lines changed: 23 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,29 @@ public class ImportServiceImpl implements ImportService {
4949

5050
private final Log logger = LogFactory.getLog(getClass());
5151

52-
@Autowired
53-
@Qualifier("domainMarshaller")
54-
private Jaxb2Marshaller jaxb2Marshaller;
55-
56-
@Autowired
57-
private AuthorizationService authorizationService;
58-
59-
@Autowired
60-
private SubscriptionService subscriptionService;
61-
62-
@Autowired
63-
private UsagePointService usagePointService;
64-
65-
@Autowired
66-
private RetailCustomerService retailCustomerService;
67-
68-
@Autowired
69-
private ResourceService resourceService;
70-
71-
@Autowired
72-
private EntryProcessorService entryProcessorService;
52+
private final Jaxb2Marshaller jaxb2Marshaller;
53+
private final AuthorizationService authorizationService;
54+
private final SubscriptionService subscriptionService;
55+
private final UsagePointService usagePointService;
56+
private final RetailCustomerService retailCustomerService;
57+
private final ResourceService resourceService;
58+
private final EntryProcessorService entryProcessorService;
59+
60+
public ImportServiceImpl(@Qualifier("domainMarshaller") Jaxb2Marshaller jaxb2Marshaller,
61+
AuthorizationService authorizationService,
62+
SubscriptionService subscriptionService,
63+
UsagePointService usagePointService,
64+
RetailCustomerService retailCustomerService,
65+
ResourceService resourceService,
66+
EntryProcessorService entryProcessorService) {
67+
this.jaxb2Marshaller = jaxb2Marshaller;
68+
this.authorizationService = authorizationService;
69+
this.subscriptionService = subscriptionService;
70+
this.usagePointService = usagePointService;
71+
this.retailCustomerService = retailCustomerService;
72+
this.resourceService = resourceService;
73+
this.entryProcessorService = entryProcessorService;
74+
}
7375

7476
// this is a list of the UsagePointIds referenced during
7577
// this import
@@ -254,63 +256,5 @@ public void importData(InputStream stream, Long retailCustomerId)
254256
}
255257
}
256258

257-
public void setJaxb2Marshaller(Jaxb2Marshaller marshaller) {
258-
this.jaxb2Marshaller = marshaller;
259-
}
260-
261-
public Jaxb2Marshaller getJaxb2Marshaller() {
262-
return this.jaxb2Marshaller;
263-
}
264-
265-
public void setAuthorizationService(
266-
AuthorizationService authorizationService) {
267-
this.authorizationService = authorizationService;
268-
}
269-
270-
public AuthorizationService getAuthorizationService() {
271-
return this.authorizationService;
272-
}
273-
274-
public void setSubscriptionService(SubscriptionService subscriptionService) {
275-
this.subscriptionService = subscriptionService;
276-
}
277-
278-
public SubscriptionService getSubscriptionService() {
279-
return this.subscriptionService;
280-
}
281-
282-
public void setUsagePointService(UsagePointService usagePointService) {
283-
this.usagePointService = usagePointService;
284-
}
285-
286-
public UsagePointService getUsagePointService() {
287-
return this.usagePointService;
288-
}
289-
290-
public void setRetailCustomerService(
291-
RetailCustomerService retailCustomerService) {
292-
this.retailCustomerService = retailCustomerService;
293-
}
294-
295-
public RetailCustomerService getRetailCustomerService() {
296-
return this.retailCustomerService;
297-
}
298-
299-
public void setResourceService(ResourceService resourceService) {
300-
this.resourceService = resourceService;
301-
}
302-
303-
public ResourceService getResourceService() {
304-
return this.resourceService;
305-
}
306-
307-
public void setEntryProcessorService(
308-
EntryProcessorService entryProcessorService) {
309-
this.entryProcessorService = entryProcessorService;
310-
}
311-
312-
public EntryProcessorService getEntryProcessorService() {
313-
return this.entryProcessorService;
314-
}
315259

316260
}

src/main/java/org/greenbuttonalliance/espi/common/service/impl/ReadingTypeServiceImpl.java

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@
3939
@Service
4040
public class ReadingTypeServiceImpl implements ReadingTypeService {
4141

42-
@Autowired
43-
private ReadingTypeRepository readingTypeRepository;
44-
45-
@Autowired
46-
private ResourceService resourceService;
42+
private final ReadingTypeRepository readingTypeRepository;
43+
private final ResourceService resourceService;
44+
private final ImportService importService;
45+
46+
public ReadingTypeServiceImpl(ReadingTypeRepository readingTypeRepository,
47+
ResourceService resourceService,
48+
ImportService importService) {
49+
this.readingTypeRepository = readingTypeRepository;
50+
this.resourceService = resourceService;
51+
this.importService = importService;
52+
}
4753

48-
@Autowired
49-
private ImportService importService;
54+
@Override
55+
public void setReadingTypeRepository(ReadingTypeRepository readingTypeRepository) {
56+
// No-op: constructor injection used, but interface requires this method
57+
}
5058

5159
@Override
5260
public ReadingType findByUUID(UUID uuid) {
@@ -144,28 +152,5 @@ public ReadingType importResource(InputStream stream) {
144152
}
145153
}
146154

147-
public void setReadingTypeRepository(ReadingTypeRepository repository) {
148-
this.readingTypeRepository = repository;
149-
}
150-
151-
public ReadingTypeRepository getReadingTypeRepository() {
152-
return this.readingTypeRepository;
153-
}
154-
155-
public void setResourceService(ResourceService resourceService) {
156-
this.resourceService = resourceService;
157-
}
158-
159-
public ResourceService getResourceService() {
160-
return this.resourceService;
161-
}
162-
163-
public void setImportService(ImportService importService) {
164-
this.importService = importService;
165-
}
166-
167-
public ImportService getImportService() {
168-
return this.importService;
169-
}
170155

171156
}

src/main/java/org/greenbuttonalliance/espi/common/service/impl/ResourceServiceImpl.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
@Service
3838
public class ResourceServiceImpl implements ResourceService {
3939

40-
@Autowired
41-
private ResourceRepository repository;
40+
private final ResourceRepository repository;
41+
42+
public ResourceServiceImpl(ResourceRepository repository) {
43+
this.repository = repository;
44+
}
4245

4346
/**
4447
* A private Map of Key:Value strings to hold the dynamic configuration.
@@ -230,9 +233,6 @@ public <T extends IdentifiedObject> Long findIdByXPath(Long id1, Long id2,
230233
return repository.findIdByXPath(id1, id2, id3, id4, clazz);
231234
}
232235

233-
public void setRepository(ResourceRepository repository) {
234-
this.repository = repository;
235-
}
236236

237237
@Override
238238
public <T extends IdentifiedObject> EntryTypeIterator findEntryTypeIterator(
@@ -319,13 +319,6 @@ public <T extends IdentifiedObject> T merge(IdentifiedObject resource) {
319319

320320
}
321321

322-
public void setResourceRepository(ResourceRepository repository) {
323-
this.repository = repository;
324-
}
325-
326-
public ResourceRepository getResourceRepository() {
327-
return this.repository;
328-
}
329322

330323
@Override
331324
public void setConfigurations(Map<String, String> params) {

0 commit comments

Comments
 (0)