473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

It is necessary that the code displays all objects

10 Byte
I wrote the code, but it displays only one object when loading, with the rest there is difficulty. Who faced similar situations, how did you solve similar situations?
And I also want to conduct a full code analysis in order to see all the errors at once, and not when loading the application into work. Are there any services?
Expand|Select|Wrap|Line Numbers
  1. public Bean inject(Bean obj) {
  2.         File file = new File("src/main/resources/data.properties");
  3.         Properties properties = new Properties();
  4.         try {
  5.             properties.load(new FileReader(file));
  6.         } catch (IOException e) {
  7.             throw new RuntimeException(e);
  8.         }
  9.         Field[] fields = obj.getClass().getDeclaredFields();
  10.         for (Field field : fields) {
  11.             field.setAccessible(true);
  12.             if (field.isAnnotationPresent(AutoInjectable.class) && field.getType() == FirstInterface.class) {
  13.                 try {
  14.                     Object someObject = null;
  15.                     try {
  16.                         Class<?> clazz = Class.forName(properties.getProperty("FirstInterface"));
  17.                         try {
  18.                             someObject = clazz.newInstance();
  19.                         } catch (InstantiationException e) {
  20.                             throw new RuntimeException(e);
  21.                         }
  22.                     } catch (ClassNotFoundException e) {
  23.                         throw new RuntimeException(e);
  24.                     }
  25.                     field.set(obj, someObject);
  26.                 } catch (IllegalAccessException e) {
  27.                     throw new RuntimeException(e);
  28.                 }
  29.             }
  30.             if (field.isAnnotationPresent(AutoInjectable.class) && field.getType() == SecondInterface.class) {
  31.                 try {
  32.                     Object someObject = null;
  33.                     try {
  34.                         Class<?> clazz = Class.forName(properties.getProperty("SecondInterface"));
  35.                         try {
  36.                             someObject = clazz.newInstance();
  37.                         } catch (InstantiationException e) {
  38.                             throw new RuntimeException(e);
  39.                         }
  40.                     } catch (ClassNotFoundException e) {
  41.                         throw new RuntimeException(e);
  42.                     }
  43.                     field.set(obj, someObject);
  44.                 } catch (IllegalAccessException e) {
  45.                     throw new RuntimeException(e);
  46.                 }
  47.             }
  48.         }
  49.         return obj;
  50.     }
Nov 25 '22 #1
0 6772

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Irmen de Jong | last post by:
What would be the best way, if any, to obtain the bytecode for a given loaded module? I can get the source: import inspect import os src = inspect.getsource(os) but there is no...
2
by: Jonathan LaRosa | last post by:
Hi all - I'm wondering if anyone has (or knows of) a tool that will allow me to search through VB code, tables, queries, reports, forms, and other objects, for references to all other types of...
2
by: **Developer** | last post by:
I've been asking about a Menu problem I have without results. So here is a test case I've developed that shows the problem. Simply create a soultion with one project containg one form and...
8
by: Wilbur Slice | last post by:
I need to write some VB.NET objects that can be called from another environment (a Progress app, specifically). I'm having some difficulty getting this to work. My first assumption was that I...
5
by: Doug Wright | last post by:
Hi The code in question is available from http://mozilla.pastebin.com/596645 Any help would be extremly appreciated, because I've spent many hours on trying to figure this out!!
0
by: ftech | last post by:
I am saving PDF files in SQL Server 2005 as an image and retrieve them back by their document ids. I use the following code: byte buffer = (byte)dtDoc.Rows; if(buffer != null) { ...
1
by: teddysnips | last post by:
I'm collaborating on a project with a colleague, sharing files through SourceSafe. So, I run GetLatestVersion and suddenly I have 264 build errors - all "Unexpected character" The file in...
1
by: Vbbeginner07 | last post by:
The follwing code is of a listview where i have to a to display the id and the name from a particular table ,empdetail. This is in the second form,dispalying id and name Private Sub Form_Load()...
2
by: Bongani Mgibi | last post by:
Hi guys please see attachment code, the code displays well with all browsers except with IE 8, if you guys can copy and paste then open it with IE then try opening it again using another browser you...
2
by: tmarynell | last post by:
I have created an SPC chart in Access. I need specific details of each data point wihtin the line graph to display when you hover over or double-click on the specific data point. It should include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.